AtCoder Beginning Contest 216
A. Signed Difficulty
1#pragma GCC optimization("O3")
2#include <bits/stdc++.h>
3using namespace std;
4typedef long long ll;
5typedef pair<int, int> pii;
6#define pb push_back
7int main()
8{
9 ios::sync_with_stdio(0), cin.tie(0);
10 int X, Y;
11 char c;
12 cin >> X >> c >> Y;
13 if (Y <= 2)
14 cout << X << "-\n";
15 else if (Y <= 6)
16 cout << X << "\n";
17 else
18 cout << X << "+\n";
19 return 0;
20}
B. Same Name
1#pragma GCC optimization("O3")
2#include <bits/stdc++.h>
3using namespace std;
4typedef long long ll;
5typedef pair<int, int> pii;
6#define pb push_back
7typedef pair<string, string> pss;
8int main()
9{
10 ios::sync_with_stdio(0), cin.tie(0);
11 int n;
12 cin >> n;
13 vector<pss> v(n);
14 for (int i = 0; i < n; i++)
15 cin >> v[i].first >> v[i].second;
16 sort(v.begin(), v.end());
17 bool same = false;
18 for (int i = 1; i < n; i++)
19 if (v[i] == v[i - 1])
20 same = true;
21 if (same)
22 cout << "Yes\n";
23 else
24 cout << "No\n";
25 return 0;
26}
C. Many Balls
1#pragma GCC optimization("O3")
2#include <bits/stdc++.h>
3using namespace std;
4typedef long long ll;
5typedef pair<int, int> pii;
6#define pb push_back
7int main()
8{
9 ios::sync_with_stdio(0), cin.tie(0);
10 ll n;
11 cin >> n;
12 string ans = "";
13 while (n)
14 {
15 if (n % 2 == 1)
16 ans = "A" + ans, n--;
17 else
18 ans = "B" + ans, n >>= 1;
19 }
20 cout << ans << "\n";
21 return 0;
22}
D. Pair of Balls
ε»ΊεεΎεζζ¨ΈζεΊγ
1#pragma GCC optimization("O3")
2#include <bits/stdc++.h>
3using namespace std;
4typedef long long ll;
5typedef pair<int, int> pii;
6#define pb push_back
7int main()
8{
9 ios::sync_with_stdio(0), cin.tie(0);
10 int n, m;
11 cin >> n >> m;
12 vector<vector<int>> v(m);
13 vector<vector<int>> G(n + 1);
14 vector<int> deg(n + 1);
15 for (int i = 0; i < m; i++)
16 {
17 int k;
18 cin >> k;
19 v[i].resize(k);
20 for (int j = 0; j < k; j++)
21 cin >> v[i][j];
22 for (int j = 1; j < k; j++)
23 G[v[i][j - 1]].pb(v[i][j]), deg[v[i][j]]++;
24 }
25 queue<int> q;
26 for (int i = 1; i <= n; i++)
27 if (deg[i] == 0)
28 q.push(i);
29 while (!q.empty())
30 {
31 int u = q.front();
32 q.pop();
33 for (int uu : G[u])
34 {
35 deg[uu]--;
36 if (deg[uu] == 0)
37 q.push(uu);
38 }
39 }
40 for (int i = 1; i <= n; i++)
41 if (deg[i])
42 {
43 cout << "No\n";
44 return 0;
45 }
46 cout << "Yes\n";
47 return 0;
48}
F. Max Sum Counting
ζεΊεΎεθε DPγ
1#pragma GCC optimization("O3")
2#pragma GCC optimization("O3")
3#include <bits/stdc++.h>
4using namespace std;
5typedef long long ll;
6typedef pair<int, int> pii;
7#define pb push_back
8const ll mod = 998244353;
9int main()
10{
11 ios::sync_with_stdio(0), cin.tie(0);
12 int n;
13 cin >> n;
14 vector<pii> v(n);
15 for (int i = 0; i < n; i++)
16 cin >> v[i].first;
17 for (int i = 0; i < n; i++)
18 cin >> v[i].second;
19 sort(v.begin(), v.end());
20 vector<ll> dp[2];
21 dp[0].resize(5001);
22 dp[1].resize(5001);
23 dp[0][0] = 1;
24 ll ans = 0;
25 for (int i = 0; i < n; i++)
26 {
27 for (int j = 5000; j >= v[i].second; j--)
28 {
29 int a = dp[0][j] + dp[1][j];
30 int b = dp[1][j - v[i].second] + dp[0][j - v[i].second];
31 dp[0][j] = a % mod;
32 dp[1][j] = b % mod;
33 if (j <= v[i].first)
34 ans = (ans + dp[1][j]) % mod;
35 }
36 }
37 cout << ans << "\n";
38 return 0;
39}