-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add '2015 Syrian Private Universities Collegiate Programming Contest'…
… solutions from CF
- Loading branch information
Showing
11 changed files
with
399 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
codeforces/2015 Syrian Private Universities Collegiate Programming Contest/A.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
#define D(x) cout << #x << " = " << (x) << endl; | ||
|
||
int main() { | ||
int t; | ||
cin >> t; | ||
|
||
while (t --> 0) { | ||
long long a, b; | ||
cin >> a >> b; | ||
cout << a * b << endl; | ||
} | ||
|
||
return 0; | ||
} |
21 changes: 21 additions & 0 deletions
21
codeforces/2015 Syrian Private Universities Collegiate Programming Contest/B.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
#define D(x) cout << #x << " = " << (x) << endl; | ||
|
||
int main() { | ||
int t; | ||
cin >> t; | ||
|
||
while (t --> 0) { | ||
long long a, b; | ||
cin >> a >> b; | ||
|
||
long long tot = (a * b) - 1; | ||
if (tot % 2 == 0) cout << "Hussain" << endl; | ||
else cout << "Hasan" << endl; | ||
} | ||
|
||
return 0; | ||
} |
31 changes: 31 additions & 0 deletions
31
codeforces/2015 Syrian Private Universities Collegiate Programming Contest/C.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
#define D(x) cout << #x << " = " << (x) << endl; | ||
|
||
int main() { | ||
int t; | ||
cin >> t; | ||
|
||
while (t --> 0) { | ||
int n; | ||
cin >> n; | ||
|
||
set<pair<int, int>> cnt; | ||
for (int it = 0; it < n; ++it) { | ||
int i, j, k; | ||
cin >> i >> j >> k; | ||
|
||
for (int a = i; a < j; ++a) { | ||
for (int b = 0; b < k; ++b) { | ||
cnt.insert({a, b}); | ||
} | ||
} | ||
} | ||
|
||
cout << cnt.size() << endl; | ||
} | ||
|
||
return 0; | ||
} |
46 changes: 46 additions & 0 deletions
46
codeforces/2015 Syrian Private Universities Collegiate Programming Contest/D.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
#define D(x) cout << #x << " = " << (x) << endl; | ||
#define IO ios::sync_with_stdio(false); cin.tie(NULL); | ||
|
||
int main() { IO | ||
int t; | ||
cin >> t; | ||
|
||
while (t --> 0) { | ||
int n; | ||
cin >> n; | ||
|
||
vector<int> v(n); | ||
set<int> pos[22222]; | ||
for (int i = 0; i < n; ++i) { | ||
cin >> v[i]; | ||
pos[v[i]].insert(i); | ||
} | ||
|
||
int best = 0; | ||
for (int i = 0; i < n; ++i) { | ||
int next = v[i] + 1; | ||
int len = 1; | ||
int ind = i; | ||
while (true) { | ||
if (pos[next].size() == 0) break; | ||
auto it = pos[next].lower_bound(ind); | ||
if (it != pos[next].end()) { | ||
next ++; | ||
ind = *it; | ||
} | ||
else break; | ||
len ++; | ||
} | ||
|
||
best = max(best, len); | ||
} | ||
|
||
cout << best << endl; | ||
} | ||
|
||
return 0; | ||
} |
28 changes: 28 additions & 0 deletions
28
codeforces/2015 Syrian Private Universities Collegiate Programming Contest/E.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
#define D(x) cout << #x << " = " << (x) << endl; | ||
|
||
bool get_color (int x, int y) { | ||
return x % 2 == y % 2; | ||
} | ||
|
||
int main() { | ||
int t; | ||
cin >> t; | ||
|
||
int n; | ||
cin >> n; | ||
|
||
while (t --> 0) { | ||
int a, b, c, d; | ||
cin >> a >> b >> c >> d; | ||
|
||
|
||
if (get_color(a, b) == get_color(c, d)) cout << max(abs(a - c), abs(b - d)) << endl; | ||
else cout << "can't reach!" << endl; | ||
} | ||
|
||
return 0; | ||
} |
43 changes: 43 additions & 0 deletions
43
codeforces/2015 Syrian Private Universities Collegiate Programming Contest/F.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
#define D(x) cout << #x << " = " << (x) << endl; | ||
|
||
int main() { | ||
int t; | ||
cin >> t; | ||
|
||
for (int j = 0; j < t; ++j) { | ||
int n; | ||
cin >> n; | ||
|
||
vector<int> v(n); | ||
for (int i = 0; i < n; ++i) cin >> v[i]; | ||
|
||
sort(v.begin(), v.end()); | ||
|
||
vector<int> solved; | ||
int tot = 0; | ||
int time = 0; | ||
for (int i = 0; i < n; ++i) { | ||
if (time + v[i] <= 300) { | ||
time += v[i]; | ||
solved.push_back(v[i]); | ||
} | ||
else break; | ||
tot ++; | ||
} | ||
|
||
int penalty = 0; | ||
int t = tot; | ||
for (int i = 0; i < solved.size(); ++i) { | ||
penalty += solved[i] * t; | ||
t --; | ||
} | ||
|
||
cout << "Case " << j + 1 << ": " << tot << " " << penalty << endl; | ||
} | ||
|
||
return 0; | ||
} |
76 changes: 76 additions & 0 deletions
76
codeforces/2015 Syrian Private Universities Collegiate Programming Contest/G.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
#define D(x) cout << #x << " = " << (x) << endl; | ||
|
||
int n, m; | ||
bool check(int x, int y) { | ||
return x < 0 || x >= n || y < 0 || y >= m; | ||
} | ||
|
||
int main() { | ||
int t; | ||
cin >> t; | ||
while (t --> 0) { | ||
cin >> n >> m; | ||
|
||
char mat[n][m]; | ||
for (int i = 0; i < n; ++i) { | ||
for (int j = 0; j < m; ++j) { | ||
cin >> mat[i][j]; | ||
} | ||
} | ||
|
||
int found = false; | ||
for (int i = 0; i < n && !found; ++i) { | ||
for (int j = 0; j < m; ++j) { | ||
if (mat[i][j] == 'p') { | ||
if (!check(i, j + 2) && mat[i][j + 1] == 'i' && mat[i][j + 2] == 'e') { | ||
found = true; | ||
break; | ||
} | ||
|
||
if (!check(i + 2, j) && mat[i + 1][j] == 'i' && mat[i + 2][j] == 'e') { | ||
found = true; | ||
break; | ||
} | ||
|
||
if (!check(i + 2, j + 2) && mat[i + 1][j + 1] == 'i' && mat[i + 2][j + 2] == 'e') { | ||
found = true; | ||
break; | ||
} | ||
|
||
if (!check(i + 2, j - 2) && mat[i + 1][j - 1] == 'i' && mat[i + 2][j - 2] == 'e') { | ||
found = true; | ||
break; | ||
} | ||
} | ||
if (mat[i][j] == 'e') { | ||
if (!check(i, j + 2) && mat[i][j + 1] == 'i' && mat[i][j + 2] == 'p') { | ||
found = true; | ||
break; | ||
} | ||
|
||
if (!check(i + 2, j) && mat[i + 1][j] == 'i' && mat[i + 2][j] == 'p') { | ||
found = true; | ||
break; | ||
} | ||
|
||
if (!check(i + 2, j + 2) && mat[i + 1][j + 1] == 'i' && mat[i + 2][j + 2] == 'p') { | ||
found = true; | ||
break; | ||
} | ||
|
||
if (!check(i + 2, j - 2) && mat[i + 1][j - 1] == 'i' && mat[i + 2][j - 2] == 'p') { | ||
found = true; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
cout << (found ? "Cutie Pie!" : "Sorry Man") << endl; | ||
} | ||
return 0; | ||
} |
64 changes: 64 additions & 0 deletions
64
codeforces/2015 Syrian Private Universities Collegiate Programming Contest/H.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
#define D(x) cout << #x << " = " << (x) << endl; | ||
|
||
int n, m, k; | ||
unsigned long long G[111][111]; | ||
|
||
void floyd (int n) { | ||
for (int k = 0; k < n; ++k){ | ||
for (int i = 0; i < n; ++i){ | ||
for (int j = 0; j < n; ++j){ | ||
G[i][j] = min(G[i][j], G[i][k] + G[k][j]); | ||
} | ||
} | ||
} | ||
} | ||
|
||
int main() { | ||
int t; | ||
cin >> t; | ||
|
||
for (int x = 0; x < t; ++x) { | ||
cin >> n >> m >> k; | ||
|
||
for (int i = 0; i < 111; ++i) | ||
for (int j = 0; j < 111; ++j) | ||
if (i == j) G[i][j] = 0; | ||
else G[i][j] = INT_MAX; | ||
|
||
for (int i = 0; i < m; ++i) { | ||
int a, b, c; | ||
cin >> a >> b >> c; | ||
G[a][b] = G[b][a] = c; | ||
} | ||
|
||
vector<int> v(k); | ||
for (int i = 0; i < k; ++i) cin >> v[i]; | ||
|
||
sort(v.begin(), v.end()); | ||
floyd(111); | ||
|
||
int ans = INT_MAX; | ||
do { | ||
int from, to; | ||
from = 1; | ||
int cost = 0; | ||
for (int i = 0; i < k; ++i) { | ||
to = v[i]; | ||
cost += G[from][to]; | ||
from = to; | ||
} | ||
|
||
cost += G[to][n]; | ||
ans = min(cost, ans); | ||
} | ||
while (next_permutation(v.begin(), v.end())); | ||
|
||
cout << "Case " << x + 1 << ": " << ans << endl; | ||
} | ||
|
||
return 0; | ||
} |
52 changes: 52 additions & 0 deletions
52
codeforces/2015 Syrian Private Universities Collegiate Programming Contest/I.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
#define D(x) cout << #x << " = " << (x) << endl; | ||
|
||
int main() { | ||
int t; | ||
cin >> t; | ||
|
||
while (t --> 0) { | ||
string s; | ||
cin >> s; | ||
|
||
vector<int> l(26, 0); | ||
for (int i = 0; i < s.size(); ++i) l[s[i] - 'a'] ++; | ||
|
||
|
||
int paila = false; | ||
string r = s; | ||
for (int i = 0, j = s.size() - 1; i < s.size() / 2; ++i, --j) { | ||
int f = false; | ||
for (int k = 0; k < 26; ++k) { | ||
if (l[k] >= 2) { | ||
l[k] -= 2; | ||
r[i] = r[j] = char(k + 'a'); | ||
f = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!f) { | ||
paila = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!paila && s.size() % 2 != 0) { | ||
for (int i = 0; i < 26; ++i) if (l[i] > 0) { | ||
l[i] --; | ||
r[s.size() / 2] = char(i + 'a'); | ||
} | ||
} | ||
|
||
int rest = accumulate(l.begin(), l.end(), 0); | ||
if (rest > 1) paila = true; | ||
|
||
cout << (paila ? "impossible": r) << endl; | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.