Salvens

A

Aug 15th, 2023
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <array>
  4. #include <vector>
  5. #include <numeric>
  6. #include <random>
  7. #include <chrono>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11.  
  12. using namespace std;
  13.  
  14. #define int long long
  15.  
  16. const int INF = 1e18 + 7;
  17. const int MAXN = 1e4 + 1000;
  18. const int N = 1e5 + 10;
  19.  
  20. array<int, MAXN> used;
  21.  
  22. void build(int v) {
  23.     int cnt = 0;
  24.     if (v % 3 == 0) {
  25.         if (v >= 1) {
  26.             if (used[v - 1] == -1) {
  27.                 build(v - 1);
  28.             }
  29.             cnt += (used[v - 1] == 0);
  30.         }
  31.         if (v >= 2) {
  32.             if (used[v - 2] == -1) {
  33.                 build(v - 2);
  34.             }
  35.             cnt += (used[v - 2] == 0);
  36.         }
  37.     }
  38.     if (v % 3 == 1) {
  39.         if (v >= 1) {
  40.             if (used[v - 1] == -1) {
  41.                 build(v - 1);
  42.             }
  43.             cnt += (used[v - 1] == 0);
  44.         }
  45.         if (v >= 3) {
  46.             if (used[v - 3] == -1) {
  47.                 build(v - 3);
  48.             }
  49.             cnt += (used[v - 3] == 0);
  50.         }
  51.     }
  52.     if (v % 3 == 2) {
  53.         if (v >= 1) {
  54.             if (used[v - 1] == -1) {
  55.                 build(v - 1);
  56.             }
  57.             cnt += (used[v - 1] == 0);
  58.         }
  59.         if (v >= 2) {
  60.             if (used[v - 2] == -1) {
  61.                 build(v - 2);
  62.             }
  63.             cnt += (used[v - 2] == 0);
  64.         }
  65.         if (v >= 3) {
  66.             if (used[v - 3] == -1) {
  67.                 build(v - 3);
  68.             }
  69.             cnt += (used[v - 3] == 0);
  70.         }
  71.     }
  72.     used[v] = (cnt > 0 ? 1 : 0);
  73. }
  74.  
  75. signed main() {
  76.     ios_base::sync_with_stdio(false);
  77.     cin.tie(nullptr);
  78.  
  79.     int n;
  80.     cin >> n;
  81.     used.fill(-1);
  82.     used[0] = 0;
  83.     build(n);
  84. //    for (int i = n; i >= 0; --i) {
  85. //        cout << used[i] << ' ';
  86. //    }
  87. //    cout << '\n';
  88.     cout << (used[n] ? 1 : 2) << '\n';
  89. }
Advertisement
Add Comment
Please, Sign In to add comment