Skip to content

Commit 1ed2cda

Browse files
committed
Added problems from CF
1 parent 6f2c54f commit 1ed2cda

File tree

4 files changed

+126
-1
lines changed

4 files changed

+126
-1
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// http://codeforces.com/contest/893/problem/A
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
#define endl '\n'
6+
#define D(x) cout << #x << " = " << (x) << endl;
7+
8+
int main() {
9+
#ifdef ONLINEJUDGE
10+
ios_base::sync_with_stdio(0); cin.tie(0);
11+
#endif
12+
13+
int n;
14+
cin >> n;
15+
16+
bool ok = true;
17+
vector<int> v = {1, 1, 0};
18+
for (int i = 0; i < n; ++i) {
19+
int x;
20+
cin >> x; x--;
21+
22+
if (!v[x]) ok = false;
23+
24+
v[x] ++;
25+
for (int j = 0; j < 3; ++j) {
26+
if (!v[j]) {
27+
v[j] = v[x];
28+
}
29+
}
30+
31+
for (int i = 0; i < 3; ++i) v[i] --;
32+
}
33+
34+
cout << (ok ? "YES" : "NO") << endl;
35+
36+
return 0;
37+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// http://codeforces.com/contest/893/problem/B
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
#define endl '\n'
6+
#define D(x) cout << #x << " = " << (x) << endl;
7+
8+
int main() {
9+
#ifdef ONLINEJUDGE
10+
ios_base::sync_with_stdio(0); cin.tie(0);
11+
#endif
12+
13+
int n;
14+
cin >> n;
15+
16+
long long ans = 0;
17+
int i = 1;
18+
while (true) {
19+
long long a = (1LL << i) - 1;
20+
long long b = 1LL << (i - 1);
21+
if (a * b > n) break;
22+
if (n % (a * b) == 0) {
23+
ans = max(ans, a * b);
24+
}
25+
26+
i ++;
27+
}
28+
29+
cout << ans << endl;
30+
return 0;
31+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// http://codeforces.com/contest/893/problem/C
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
#define endl '\n'
6+
#define D(x) cout << #x << " = " << (x) << endl;
7+
8+
const int MX = 1e5 + 100;
9+
vector<int> G[MX];
10+
vector<long long> v(MX);
11+
vector<int> visited(MX, 0);
12+
long long mm;
13+
14+
void dfs (int cur) {
15+
if (!visited[cur]) {
16+
mm = min(v[cur], mm);
17+
visited[cur] = true;
18+
for (int i = 0; i < G[cur].size(); ++i) {
19+
int next = G[cur][i];
20+
mm = min(mm, v[next]);
21+
dfs(next);
22+
}
23+
24+
}
25+
}
26+
27+
int main() {
28+
#ifdef ONLINEJUDGE
29+
ios_base::sync_with_stdio(0); cin.tie(0);
30+
#endif
31+
32+
int n, m;
33+
while (cin >> n >> m) {
34+
for (int i = 1; i <= n; ++i) cin >> v[i];
35+
36+
for (int i = 0; i < m; ++i) {
37+
int a, b;
38+
cin >> a >> b;
39+
G[a].push_back(b);
40+
G[b].push_back(a);
41+
}
42+
43+
long long ans = 0;
44+
for (int i = 1; i <= n; ++i) {
45+
if (!visited[i]) {
46+
mm = INT_MAX;
47+
dfs(i);
48+
ans += mm;
49+
}
50+
}
51+
52+
cout << ans << endl;
53+
}
54+
55+
return 0;
56+
}

codeforces/data.db

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,4 +1066,5 @@
10661066
32302138
10671067
32161457
10681068
31878123
1069-
31910741
1069+
31910741
1070+
32605600

0 commit comments

Comments
 (0)