Advertisement
Korotkodul

N4 30 из 100

Oct 25th, 2022 (edited)
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.63 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 n) {
  51.     return (2 * a1 + n - 1) * n / 2;
  52. }
  53.  
  54. ll n, m;
  55.  
  56. ll frx, tox, fry, toy;
  57.  
  58. bool ok(int i, int j) {
  59.     return i >= frx && i <= tox && j >= fry && j <= toy;
  60. }
  61. vector <int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
  62.  
  63. bool sh = 0;
  64. int main() {
  65.     ios::sync_with_stdio(0);
  66.     cin.tie(0);
  67.     cout.tie(0);
  68.     cin >> n >> m;
  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.     while (1) {
  82.         //cnt +=
  83.         while ( ok(i + dx[to], j + dy[to]) ) {
  84.             i += dx[to];
  85.             j += dy[to];
  86.             a[i][j] = 1;
  87.             cnt++;
  88.         }
  89.         if (sh) {
  90.             cout << "to = " << to << "\n";
  91.             cout << "frx tox = " << frx << ' ' << tox << "\n";
  92.             cout << "fry toy = " << fry << ' ' << toy << "\n";
  93.         }
  94.         if (to == 0) {
  95.             frx += 2;
  96.             //tox -= 2;
  97.         }
  98.         else if (to == 2) {
  99.             tox -= 2;
  100.         }
  101.         else if (to == 1) {
  102.             fry += 2;
  103.         }
  104.         else if (to == 3) {
  105.             toy -= 2;
  106.         }
  107.         to++;
  108.         to %= 4;
  109.         if (sh) {
  110.             cout << "to = " << to << "\n";
  111.             cout << "i + dx[to] j + dy[to] = " << i + dx[to] << ' ' << j + dy[to] << "\n";
  112.         }
  113.         if (!ok(i + dx[to], j + dy[to])) {
  114.             break;
  115.         }
  116.     }
  117.     if (sh) {
  118.         cout << "i j = " << i << ' ' << j << "\n";
  119.         cout << "to = " << to << "\n";
  120.         cout << "ans\n";
  121.     }
  122.     cout << cnt << "\n";
  123.     if (sh) {
  124.         cvv(a);
  125.     }
  126. }
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement