Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- task 2
- int imp (int a, int b) {
- if (a == 1 && b == 0) return 0;
- return 1;
- }
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- fr (x, 2) {
- fr (y, 2) {
- fr (z, 2) {
- fr (w, 2) {
- int a = imp (y, w);
- int b = imp (x, 1 - z);
- int c = a == b;
- int d = x || w;
- int e = c && d;
- cerr << x << ' ' << y << ' ' << z << ' ' << w << ' ' << e << '\n';
- }
- }
- }
- }
- }
- task 5
- int kek (int n) {
- vector<int> goo;
- while (n) {
- goo.pb (n % 2);
- n /= 2;
- }
- reverse (all (goo));
- while (!goo.empty () && goo.back () == 0) goo.pop_back ();
- int ans = 0;
- fr (i, sz (goo)) ans += (1<<i) * goo[i];
- return ans;
- }
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- for (int i = 100; i > 0; --i) {
- if (kek (i) == 13) {
- dbg (i);
- exit (0);
- }
- }
- }
- task 6
- int kek (int s) {
- int n = 1;
- while (s > 200) {
- s -= 15;
- n += 3;
- }
- return n;
- }
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- for (int i = 10000; i > 0; --i) {
- if (kek (i) == 46) {
- dbg (i);
- exit (0);
- }
- }
- }
- task 8
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- string s = "OLQGA";
- sort (all (s));
- int ans = 0;
- do {
- int f = 1;
- if (s.front () == 'Q') f = 0;
- else {
- fl (i, 1, sz (s)) {
- if (s[i] == 'Q') {
- if (s[i - 1] == 'O' || s[i - 1] == 'A') f = 0;
- }
- }
- }
- ans += f;
- } while (next_permutation (all (s)));
- dbg (ans);
- }
- task 14
- x = 343 ** 5 + 343 ** 4 + 49 ** 6 - 7 ** 13 - 21
- a = set ()
- while (x > 0):
- a.add (x % 7)
- x //= 7
- # print (a)
- print (len (a))
- task 15
- int check (int a, int x, int y) {
- int b = y > a;
- int c = x > a;
- int d = x * y < 120;
- return b || c || d;
- }
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- for (int a = 10000; a >= 0; --a) {
- int f = 1;
- fr (x, 1000) fr (y, 1000) f &= check (a, x, y);
- if (f) {
- dbg (a);
- exit (0);
- }
- }
- }
- task 16
- int g(int);
- int f (int n) {
- if (n == 1) return 1;
- return 2 * f (n - 1) - g (n - 1);
- }
- int g (int n) {
- if (n == 1) return 1;
- return f (n - 1) + 2 * g (n - 1);
- }
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- dbg (g (25) + f (25));
- }
- task 17
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- int cnt = 0, mx = 0;
- fl (i, 100, 10000 + 1) {
- if (i % 10 == 3) {
- if (i % 8 == 7) {
- vector<int> a{13, 16, 19};
- int f = 1;
- for (auto& x: a) if (i % x == 0) f = 0;
- if (f && i % 21 == 0) {
- ++cnt;
- mx = i;
- }
- }
- }
- }
- dbg (cnt);
- dbg (mx);
- }
- task 18
- const int n = 12;
- array <array <int, n>, n> goo, dp1, dp2;
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- for (auto& v: goo) for (auto& x: v) cin >> x;
- fr (i, n) fr (j, n) {
- int mx = 0, mn = 1e9;
- if (goo[i][j] > 100) {
- dp1[i][j] = -1e18;
- dp2[i][j] = 1e18;
- continue;
- }
- if (i > 0) {
- mx = max (mx, dp1[i - 1][j]);
- mn = min (mn, dp2[i - 1][j]);
- }
- if (j > 0) {
- mx = max (mx, dp1[i][j - 1]);
- mn = min (mn, dp2[i][j - 1]);
- }
- dp1[i][j] = mx + goo[i][j], dp2[i][j] = mn + goo[i][j];
- if (mn == 1e9) dp1[i][j] = dp2[i][j] = goo[i][j];
- }
- cout << dp1[n - 1][n - 1] << ' ' << dp2[n - 1][n - 1] << '\n';
- }
- task 20
- array <array <int, 100>, 100> dp;
- vector<pair<int, int>> gen (int a, int b) {
- return {{a + 1, b}, {a * 2, b}, {a, b + 1}, {a, b * 2}};
- }
- int calc (int a, int b) {
- if (a + b >= 39) return 0;
- if (dp[a][b] != -1) return dp[a][b];
- auto t = gen (a, b);
- int cnt = 0;
- for (auto& x: t) cnt += calc (x.first, x.second);
- if (cnt == sz (t)) return dp[a][b] = 0;
- return dp[a][b] = 1;
- }
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- for (auto& v: dp) for (auto& x: v) x = -1;
- fl (i, 1, 30) {
- if (calc (i, 9)) {
- auto t = gen (i, 9);
- int f = 0;
- for (auto& x: t) {
- if (x.first + x.second >= 39) f = 1;
- }
- if (!f) {
- // dbg (make_pair (i, 9));
- f = 0;
- for (auto& x: t) {
- if (calc (x.first, x.second)) continue;
- // dbg (x);
- int c = 0;
- auto tt = gen (x.first, x.second);
- for (auto& xx: tt) {
- // dbg (xx);
- int ff = 0;
- auto ttt = gen (xx.first, xx.second);
- for (auto& xxx: ttt) {
- if (xxx.first + xxx.second >= 39) ff = 1;
- // dbg (xxx);
- }
- c += ff;
- }
- if (c == sz (tt)) f = 1;
- }
- if (f) {
- cout << i << ' ';
- // exit (0);
- }
- }
- }
- }
- }
- task 21
- array <array <int, 100>, 100> dp;
- vector<pair<int, int>> gen (int a, int b) {
- return {{a + 1, b}, {a * 2, b}, {a, b + 1}, {a, b * 2}};
- }
- int calc (int a, int b) {
- if (a + b >= 39) return 0;
- if (dp[a][b] != -1) return dp[a][b];
- auto t = gen (a, b);
- int cnt = 0;
- for (auto& x: t) cnt += calc (x.first, x.second);
- if (cnt == sz (t)) return dp[a][b] = 0;
- return dp[a][b] = 1;
- }
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- for (auto& v: dp) for (auto& x: v) x = -1;
- fl (i, 1, 30) {
- if (!calc (i, 9)) {
- auto t = gen (i, 9);
- int cnt1 = 0, j = 0;
- vector<int> used (sz (t));
- for (auto& x: t) {
- int f = 0;
- auto tt = gen (x.first, x.second);
- for (auto& xx: tt) {
- if (xx.first + xx.second >= 39) f = 1;
- }
- cnt1 += f;
- used[j] = f;
- ++j;
- }
- if (cnt1 > 0 && cnt1 < sz (t)) {
- j = 0;
- for (auto& x: t) {
- if (!used[j]) {
- int f = 0;
- auto tt = gen (x.first, x.second);
- for (auto& xx: tt) {
- if (calc (xx.first, xx.second)) continue;
- int c = 0;
- auto ttt = gen (xx.first, xx.second);
- for (auto& xxx: ttt) {
- int ff = 0;
- auto tttt = gen (xxx.first, xxx.second);
- for (auto& xxxx: tttt) {
- if (xxxx.first + xxxx.second >= 39) ff = 1;
- }
- c += ff;
- }
- if (c == sz (ttt)) f = 1;
- }
- cnt1 += f;
- }
- ++j;
- }
- if (cnt1 == sz (t)) cout << i << ' ';
- }
- }
- }
- }
- task 22
- int kek (int x) {
- int a = 0, b = 0;
- while (x > 0) {
- a += x % 8;
- ++b;
- x /= 8;
- }
- return a * b;
- }
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- fl (i, 1, 1000) {
- if (kek (i) == 20) {
- dbg (i);
- exit (0);
- }
- }
- }
- task 23
- array<int, 100> dp;
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- dp[1] = 1;
- fl (i, 1, 31) {
- if (i < 14) {
- if (i + 2 <= 14) dp[i + 2] += dp[i];
- if (i * 2 <= 14) dp[i * 2] += dp[i];
- } else {
- dp[i + 2] += dp[i];
- dp[i * 2] += dp[i];
- }
- }
- dbg (dp[30]);
- }
- task 24
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- vector<string> goo;
- for (string s; cin >> s; ) goo.pb (s);
- int mn = 1e9;
- int pos = -1;
- fr (i, sz (goo)) {
- int cnt = 0;
- for (auto& x: goo[i]) cnt += x == 'A';
- if (cnt < mn) {
- mn = cnt;
- pos = i;
- }
- }
- map <char, int> cnt;
- for (auto& x: goo[pos]) ++cnt[x];
- int mx = 0;
- char kek;
- for (auto& x: cnt) {
- if (x.second >= mx) {
- mx = x.second;
- kek = x.first;
- }
- }
- cout << kek << ' ';
- int c = 0;
- for (auto& s: goo) for (auto& x: s) c += x == kek;
- cout << c << '\n';
- }
- task 25
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- int cnt = 0;
- int mx = 0;
- int kek = 0;
- fl (a, 1, 5000 + 1) {
- fl (b, a, 5000 + 1) {
- int c = a * a + b * b;
- int c_kek = sqrt(c);
- if (c_kek * c_kek == c && c_kek <= 5000) {
- ++cnt;
- if (a + b + c_kek > mx) {
- mx = a + b + c_kek;
- kek = c_kek;
- }
- cerr << a << ' ' << b << ' ' << c_kek << '\n';
- }
- }
- }
- cout << cnt << ' ' << kek << '\n';
- }
- task 26
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- int n;
- cin >> n;
- vector<int> goo (n);
- for (auto& x: goo) cin >> x;
- unordered_set<int> kek;
- for (auto& x: goo) kek.insert (x);
- int cnt = 0, mx = 0;
- fr (i, n) {
- if (goo[i] % 2 == 0) continue;
- fl (j, i + 1, n) {
- if (goo[j] % 2 == 0) continue;
- if (kek.count ((goo[i] + goo[j]) / 2)) {
- ++cnt;
- mx = max (mx, (goo[i] + goo[j]) / 2);
- }
- }
- }
- cout << cnt << ' ' << mx << '\n';
- }
- task 27
- signed main () {
- ios_base::sync_with_stdio (0);
- cin.tie (0);
- int n;
- cin >> n;
- vector<int> goo (n);
- for (auto& x: goo) cin >> x;
- vector<int> mx1 (80), mx2 (80);
- for (auto& x: goo) {
- if (x > mx1[x % 80]) {
- mx2[x % 80] = mx1[x % 80];
- mx1[x % 80] = x;
- } else if (x > mx2[x % 80]) {
- mx2[x % 80] = x;
- }
- }
- int mx = 0;
- fr (i, 80) {
- if (mx2[i] > 0) mx = max (mx, mx1[i] + mx2[i]);
- }
- cout << mx << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement