Advertisement
Korotkodul

N4 100 из 100

Oct 25th, 2022 (edited)
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int, int>
  11. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v) {
  17.     for (auto x : v) cout << x << ' ';
  18.     cout << "\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v) {
  22.     for (auto x : v) cout << x << ' ';
  23.     cout << "\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v) {
  28.     for (auto x : v) cv(x);
  29.     cout << "\n";
  30. }
  31.  
  32. void cvb(vector <bool> v) {
  33.     for (bool x : v) cout << x << ' ';
  34.     cout << "\n";
  35. }
  36.  
  37. void cvs(vector <string>  v) {
  38.     for (auto a : v) {
  39.         cout << a << "\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a) {
  44.     for (auto p : a) {
  45.         cout << p.first << ' ' << p.second << "\n";
  46.     }
  47.     cout << "\n";
  48. }
  49.  
  50. ll S(ll a1, ll d, ll n) {
  51.     return (2 * a1 + d * (n - 1) ) * n / 2;
  52. }
  53.  
  54.  
  55. ll frx, tox, fry, toy;
  56.  
  57. bool ok(int i, int j) {
  58.     return i >= frx && i <= tox && j >= fry && j <= toy;
  59. }
  60. vector <int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
  61.  
  62. bool sh = 1;
  63. ll n, m;
  64. // 10 11
  65. ll dull () {
  66.     ios::sync_with_stdio(0);
  67.     cin.tie(0);
  68.     cout.tie(0);
  69.     frx = -2;
  70.     tox = n - 1;
  71.     fry = 0;
  72.     toy = m - 1;
  73.     ll cnt = 1;
  74.     vector <vector <int> > a(n, vector <int> (m, 0));
  75.     if (min(n, m) == 1) {
  76.         cout << n * m;
  77.         exit(0);
  78.     }
  79.     a[0][0] = 1;
  80.     int i = 0, j = 0, to = 0;
  81.     ll k = 0;
  82.     while (1) {
  83.         //cnt +=
  84.         while ( ok(i + dx[to], j + dy[to]) ) {
  85.             i += dx[to];
  86.             j += dy[to];
  87.             a[i][j] = 1;
  88.             cnt++;
  89.         }
  90.         /*if (sh) {
  91.             cout << "to = " << to << "\n";
  92.             cout << "frx tox = " << frx << ' ' << tox << "\n";
  93.             cout << "fry toy = " << fry << ' ' << toy << "\n";
  94.         }*/
  95.         k++;
  96.         if (to == 0) {
  97.             frx += 2;
  98.             //tox -= 2;
  99.         }
  100.         else if (to == 2) {
  101.             tox -= 2;
  102.         }
  103.         else if (to == 1) {
  104.             fry += 2;
  105.         }
  106.         else if (to == 3) {
  107.             toy -= 2;
  108.         }
  109.         to++;
  110.         to %= 4;
  111.         /*if (sh) {
  112.             cout << "to = " << to << "\n";
  113.             cout << "i + dx[to] j + dy[to] = " << i + dx[to] << ' ' << j + dy[to] << "\n";
  114.         }*/
  115.         if (!ok(i + dx[to], j + dy[to])) {
  116.             break;
  117.         }
  118.     }
  119.     /*if (sh) {
  120.         cout << "i j = " << i << ' ' << j << "\n";
  121.         cout << "to = " << to << "\n";
  122.         cout << "ans\n";
  123.     }*/
  124.  
  125.     if (sh) {
  126.         cvv(a);
  127.     }
  128.     if (sh) {
  129.         cout << "dull k = " << k << "\n\n\n";
  130.     }
  131.     return cnt;
  132. }
  133.  
  134. bool ok(ll k) {
  135.     ll resx, resy;
  136.     ll gox = k / 2 + k % 2;
  137.     if (gox == 1) {
  138.         resx = n;
  139.     } else {
  140.         resx = n - (1 + 2 * (gox - 2));
  141.     }
  142.  
  143.     ll goy = k / 2;
  144.     resy = m - (1 + 2 * (goy - 1));
  145.     if (sh) {
  146.         cout << "check\n";
  147.         cout << "k = " << k << "\n";
  148.         cout << "gox goy = " << gox << ' ' << goy << "\n";
  149.         cout << "resx resy = " << resx << ' ' << resy << "\n";
  150.         cout << "\n";
  151.     }
  152.  
  153.     if (k % 2 == 0 && resx < 2) {
  154.         return 0;
  155.     }
  156.     if (k % 2 == 1 && resy < 2) {
  157.         return 0;
  158.     }
  159.  
  160.     bool r = min(resy, resx) >= 0;
  161.     return r;
  162. }
  163.  
  164. ll get(ll k) {
  165.     ll gox = k / 2 + k % 2;
  166.     ll goy = k / 2;
  167.     ll Sn, Sm;
  168.     Sn = S(n - 1, -2, gox - 1) + n;
  169.     Sm = S(m - 1, -2, goy);
  170.     ll r = Sn + Sm;
  171.     if (sh) {
  172.         cout << "get\n";
  173.         cout << "gox goy = " << gox << ' ' << goy << "\n";
  174.         cout << "Sn Sm = " << Sn << ' ' << Sm << "\n";
  175.         cout << "r = " << r << "\n";
  176.     }
  177.  
  178.     return r;
  179. }
  180.  
  181. ll my() {
  182.     ll L = 0, R = max(n, m) * 2, med;
  183.     while (L + 1 < R) {
  184.         med = (L + R) / 2;
  185.         if (sh) {
  186.             cout << "med = " << med << "\n";
  187.         }
  188.         if (ok(med)) {
  189.             L = med;
  190.         } else {
  191.             R = med;
  192.         }
  193.     }
  194.  
  195.     if (sh) {
  196.         cout << "L = " << L << "\n";
  197.         cout << "\n\n";
  198.     }
  199.  
  200.     ll ans = get(L);
  201.     return ans;
  202. }
  203. // 10 20
  204. int main() {
  205.     cin >> n >> m;
  206.     ll he = dull();
  207.     ll me = my();
  208.     cout << "n m = " << n << ' ' << m << "\n";
  209.     cout << "me he = " << me << ' '<< he << "\n";
  210.     if (me == he) {
  211.         cout << "OK\n";
  212.     }
  213.     else {
  214.  
  215.         cout << "WA\n";
  216.     }
  217. }
  218.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement