Skip to content

Commit 8853317

Browse files
committed
cf round problems a, b, c, d, e
1 parent 0a7f156 commit 8853317

File tree

5 files changed

+492
-0
lines changed

5 files changed

+492
-0
lines changed

Codeforces/1472A.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#include <bits/stdc++.h>
2+
3+
#define FOR(i, b, e, s) for(int i=(b); (s)>0?i<(e):i>(e); i+=(s))
4+
#define FOR1(e) FOR(i, 0, e, 1)
5+
#define FOR2(i, e) FOR(i, 0, e, 1)
6+
#define FOR3(i, b, e) FOR(i, b, e, 1)
7+
#define FOR4(i, b, e, s) FOR(i, b, e, s)
8+
#define GET5(a, b, c, d, e, ...) e
9+
#define FORC(...) GET5(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)
10+
#define range(...) FORC(__VA_ARGS__)(__VA_ARGS__)
11+
#define each(x, a) for (auto& x: a)
12+
13+
#define vk vector
14+
#define st first
15+
#define nd second
16+
#define pb push_back
17+
#define mp make_pair
18+
19+
using namespace std;
20+
21+
template<class T> void read(T& x) {
22+
cin >> x;
23+
}
24+
void read(double& d) {
25+
string t;
26+
read(t);
27+
d=stod(t);
28+
}
29+
void read(long double& d) {
30+
string t;
31+
read(t);
32+
d=stold(t);
33+
}
34+
template<class H, class... T> void read(H& h, T&... t) {
35+
read(h);
36+
read(t...);
37+
}
38+
template<class A> void read(vk<A>& x) {
39+
each(a, x)
40+
read(a);
41+
}
42+
43+
typedef long long ll;
44+
typedef long double ld;
45+
typedef vector<int> vi;
46+
typedef vector<vi> vvi;
47+
typedef pair<int, int> pii;
48+
typedef vector<pii> vii;
49+
50+
const int MOD = 1e9+7;
51+
52+
53+
54+
55+
void solve() {
56+
//
57+
int w, h, n;
58+
read(w, h, n);
59+
60+
int x = w, v = h;
61+
while(w%2 == 0)
62+
w /= 2;
63+
while(h%2 == 0)
64+
h /= 2;
65+
66+
int t = (x/w) * (v/h);
67+
cout << (t >= n ? "Yes" : "No") << "\n";
68+
69+
}
70+
71+
int main() {
72+
ios::sync_with_stdio(false);
73+
74+
int tests;
75+
read(tests);
76+
77+
range(tests)
78+
solve();
79+
}

Codeforces/1472B.cpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include <bits/stdc++.h>
2+
3+
#define FOR(i, b, e, s) for(int i=(b); (s)>0?i<(e):i>(e); i+=(s))
4+
#define FOR1(e) FOR(i, 0, e, 1)
5+
#define FOR2(i, e) FOR(i, 0, e, 1)
6+
#define FOR3(i, b, e) FOR(i, b, e, 1)
7+
#define FOR4(i, b, e, s) FOR(i, b, e, s)
8+
#define GET5(a, b, c, d, e, ...) e
9+
#define FORC(...) GET5(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)
10+
#define range(...) FORC(__VA_ARGS__)(__VA_ARGS__)
11+
#define each(x, a) for (auto& x: a)
12+
13+
#define vk vector
14+
#define st first
15+
#define nd second
16+
#define pb push_back
17+
#define mp make_pair
18+
19+
using namespace std;
20+
21+
template<class T> void read(T& x) {
22+
cin >> x;
23+
}
24+
void read(double& d) {
25+
string t;
26+
read(t);
27+
d=stod(t);
28+
}
29+
void read(long double& d) {
30+
string t;
31+
read(t);
32+
d=stold(t);
33+
}
34+
template<class H, class... T> void read(H& h, T&... t) {
35+
read(h);
36+
read(t...);
37+
}
38+
template<class A> void read(vk<A>& x) {
39+
each(a, x)
40+
read(a);
41+
}
42+
43+
typedef long long ll;
44+
typedef long double ld;
45+
typedef vector<int> vi;
46+
typedef vector<vi> vvi;
47+
typedef pair<int, int> pii;
48+
typedef vector<pii> vii;
49+
50+
const int MOD = 1e9+7;
51+
52+
53+
54+
55+
void solve() {
56+
//
57+
int n;
58+
read(n);
59+
60+
vi have(2);
61+
vi a(n);
62+
each(x, a) {
63+
read(x);
64+
have[x-1]++;
65+
}
66+
67+
int xx = have[0];
68+
int vv = have[1];
69+
70+
if(vv % 2 == 0 && xx % 2 == 0) {
71+
cout << "Yes\n";
72+
return;
73+
}
74+
if(vv % 2 == 1 && ((xx>=2) && ((xx-2) % 2 == 0))) {
75+
cout << "Yes\n";
76+
return;
77+
}
78+
79+
cout << "No\n";
80+
}
81+
82+
int main() {
83+
ios::sync_with_stdio(false);
84+
85+
int tests;
86+
read(tests);
87+
88+
range(tests)
89+
solve();
90+
}

Codeforces/1472C.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include <bits/stdc++.h>
2+
3+
#define FOR(i, b, e, s) for(int i=(b); (s)>0?i<(e):i>(e); i+=(s))
4+
#define FOR1(e) FOR(i, 0, e, 1)
5+
#define FOR2(i, e) FOR(i, 0, e, 1)
6+
#define FOR3(i, b, e) FOR(i, b, e, 1)
7+
#define FOR4(i, b, e, s) FOR(i, b, e, s)
8+
#define GET5(a, b, c, d, e, ...) e
9+
#define FORC(...) GET5(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)
10+
#define range(...) FORC(__VA_ARGS__)(__VA_ARGS__)
11+
#define each(x, a) for (auto& x: a)
12+
13+
#define vk vector
14+
#define st first
15+
#define nd second
16+
#define pb push_back
17+
#define mp make_pair
18+
19+
using namespace std;
20+
21+
template<class T> void read(T& x) {
22+
cin >> x;
23+
}
24+
void read(double& d) {
25+
string t;
26+
read(t);
27+
d=stod(t);
28+
}
29+
void read(long double& d) {
30+
string t;
31+
read(t);
32+
d=stold(t);
33+
}
34+
template<class H, class... T> void read(H& h, T&... t) {
35+
read(h);
36+
read(t...);
37+
}
38+
template<class A> void read(vk<A>& x) {
39+
each(a, x)
40+
read(a);
41+
}
42+
43+
typedef long long ll;
44+
typedef long double ld;
45+
typedef vector<int> vi;
46+
typedef vector<vi> vvi;
47+
typedef pair<int, int> pii;
48+
typedef vector<pii> vii;
49+
50+
const int MOD = 1e9+7;
51+
52+
53+
54+
55+
void solve() {
56+
//
57+
int n;
58+
read(n);
59+
60+
vi a(n);
61+
read(a);
62+
63+
int mx = -1;
64+
vk<ll> dp(n);
65+
range(i, n-1, -1, -1) {
66+
dp[i] = 1ll * a[i];
67+
if(i + a[i] < n)
68+
dp[i] += dp[i+a[i]];
69+
if(mx < dp[i])
70+
mx = dp[i];
71+
}
72+
cout << mx << "\n";
73+
}
74+
75+
int main() {
76+
ios::sync_with_stdio(false);
77+
78+
int tests;
79+
read(tests);
80+
81+
range(tests)
82+
solve();
83+
}

Codeforces/1472D.cpp

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#include <bits/stdc++.h>
2+
3+
#define FOR(i, b, e, s) for(int i=(b); (s)>0?i<(e):i>(e); i+=(s))
4+
#define FOR1(e) FOR(i, 0, e, 1)
5+
#define FOR2(i, e) FOR(i, 0, e, 1)
6+
#define FOR3(i, b, e) FOR(i, b, e, 1)
7+
#define FOR4(i, b, e, s) FOR(i, b, e, s)
8+
#define GET5(a, b, c, d, e, ...) e
9+
#define FORC(...) GET5(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)
10+
#define range(...) FORC(__VA_ARGS__)(__VA_ARGS__)
11+
#define each(x, a) for (auto& x: a)
12+
13+
#define vk vector
14+
#define st first
15+
#define nd second
16+
#define pb push_back
17+
#define mp make_pair
18+
19+
using namespace std;
20+
21+
template<class T> void read(T& x) {
22+
cin >> x;
23+
}
24+
void read(double& d) {
25+
string t;
26+
read(t);
27+
d=stod(t);
28+
}
29+
void read(long double& d) {
30+
string t;
31+
read(t);
32+
d=stold(t);
33+
}
34+
template<class H, class... T> void read(H& h, T&... t) {
35+
read(h);
36+
read(t...);
37+
}
38+
template<class A> void read(vk<A>& x) {
39+
each(a, x)
40+
read(a);
41+
}
42+
43+
typedef long long ll;
44+
typedef long double ld;
45+
typedef vector<int> vi;
46+
typedef vector<vi> vvi;
47+
typedef pair<int, int> pii;
48+
typedef vector<pii> vii;
49+
50+
const int MOD = 1e9+7;
51+
52+
53+
54+
55+
56+
void solve() {
57+
//
58+
int n;
59+
read(n);
60+
61+
vi odd, even;
62+
range(i, n) {
63+
int x;
64+
read(x);
65+
if(x%2)
66+
odd.pb(x);
67+
else
68+
even.pb(x);
69+
}
70+
71+
sort(odd.begin(), odd.end());
72+
sort(even.begin(), even.end());
73+
74+
int lo = int(odd.size()) - 1;
75+
int le = int(even.size()) - 1;
76+
77+
int ind = 0;
78+
ll even_sum = 0, odd_sum = 0;
79+
while(lo >= 0 && le >= 0) {
80+
ind++;
81+
if(ind%2) {
82+
if(even[le] > odd[lo])
83+
even_sum += 1ll * even[le--];
84+
else
85+
lo--;
86+
} else {
87+
if(odd[lo] > even[le])
88+
odd_sum += 1ll * odd[lo--];
89+
else
90+
le--;
91+
}
92+
}
93+
//cout << "os: " << odd_sum << " : es: " << even_sum << "\n";
94+
if(lo == -1) {
95+
while(le >= 0) {
96+
ind++;
97+
if(ind%2)
98+
even_sum += 1ll * even[le];
99+
le--;
100+
}
101+
} else {
102+
while(lo >= 0) {
103+
ind++;
104+
if(ind%2 == 0)
105+
odd_sum += 1ll * odd[lo];
106+
lo--;
107+
}
108+
}
109+
//cout << "os: " << odd_sum << " : es: " << even_sum << "\n";
110+
cout << (odd_sum == even_sum ? "Tie" : (odd_sum > even_sum ? "Bob" : "Alice")) << "\n";
111+
}
112+
113+
int main() {
114+
ios::sync_with_stdio(false);
115+
116+
int tests;
117+
read(tests);
118+
119+
range(tests)
120+
solve();
121+
}

0 commit comments

Comments
 (0)