trafik

Untitled

Jul 18th, 2023
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.32 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. //#include <ext/pb_ds/assoc_container.hpp> // Общий файл.
  3. //#include <ext/pb_ds/tree_policy.hpp> // Содержит класс tree_order_statistics_node_update
  4.  
  5. #define ll long long
  6. #define ull unsigned long long
  7. #define ld long double
  8. #define len(v) (int)v.size()
  9. #define all(v) v.begin(), v.end()
  10. #define rall(v) v.rbegin(), v.rend()
  11. #define pii pair<int, int>
  12. #define vi vector<int>
  13. #define vii vector<vector<int>>
  14. #define vpii vector<pair<int, int>>
  15. #define dcout cout << setprecision(7)
  16. #define mkp make_pair
  17. #define in(v) for (auto& i : v) cin >> i;
  18. #define out(v) for (auto& i : v) cout << i << ' ';
  19. //#define int long long
  20. //#define ll ull
  21. const int maxn = 3e5 + 10;
  22. const int C = 20;
  23. const int logn = 20;
  24. const int inf = 1e9;
  25. const ll mod = 1e9 + 7;
  26. //const int M = 1e9;
  27. const ull M2 = 998244353;
  28. const ld eps = 1e-9;
  29. using namespace std;
  30. //using namespace __gnu_pbds;
  31.  
  32. //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  33.  
  34.  
  35. // random
  36. //std::mt19937_64 gen(std::chrono::steady_clock::now().time_since_epoch().count());
  37.  
  38. int gcd(int a, int b) {
  39.     return b ? gcd(b, a % b) : a;
  40. }
  41.  
  42. ll binpow(ll a, ll p, ll m) {
  43.     if (p == 0) return 1ll;
  44.     else if (p % 2)
  45.         return (binpow(a, p - 1, m) * a) % m;
  46.     else {
  47.         ll d = binpow(a, p / 2, m);
  48.         return (int)((d * d) % m);
  49.     }
  50. }
  51.  
  52. ll binsqrt(ll x) {
  53.     ll l = 0;
  54.     ll r = 1000000;
  55.     for (int i = 0; i < 200; ++i) {
  56.         ll m = (l + r) / 2;
  57.         if (m * m < x) l = m;
  58.         else r = m;
  59.     }
  60.     return r;
  61. }
  62.  
  63. int gcd_ext(int a, int b, int& x, int& y) {
  64.     if (b == 0) {
  65.         x = 1;
  66.         y = 0;
  67.         return a;
  68.     }
  69.     int xx, yy, d;
  70.     d = gcd_ext(b, a % b, xx, yy);
  71.     x = yy;
  72.     y = xx - (a / b) * yy;
  73.     return d;
  74. }
  75.  
  76. ll phi(ll n) {
  77.     ll res = n;
  78.     for (int i = 2; i * i <= n; ++i) {
  79.         if (n % i == 0) {
  80.             while (n % i == 0)
  81.                 n /= i;
  82.             res -= res / i;
  83.         }
  84.     }
  85.     if (n > 1)
  86.         res -= res / n;
  87.     return res;
  88. }
  89.  
  90. void solve() {
  91.     int n, l = -1; cin >> n;
  92.     vi c(n); in(c);
  93.  
  94.     for (int i = 0; i < n; ++i) {
  95.         if (c[i] == 0) {
  96.             if (l == -1) {
  97.                 l = i;
  98.                 continue;
  99.             } else {
  100.                 cout << "NO";
  101.                 return;
  102.             }
  103.         }
  104.         if (c[i] == 2) {
  105.             if (l == -1) {
  106.                 l = i;
  107.                 continue;
  108.             } else if (i - l != 2) {
  109.                 cout << "NO";
  110.                 return;
  111.             }
  112.         }
  113.     }
  114.  
  115.     vi a;
  116.     for (int i = l; i < n; ++i)
  117.         a.push_back(c[i]);
  118.     for (int i = 0; i < l; ++i)
  119.         a.push_back(c[i]);
  120.     //out(a);
  121.     for (int i = 0; i < n; ++i) {
  122.         int cur = i + 1;
  123.         if (abs(a[i] - cur) != 1) {
  124.             cout << "NO";
  125.             return;
  126.         }
  127.         a[i] += (a[i] > cur ? -1 : 1);
  128.     }
  129.     for (int i = 1; i <= n; ++i) {
  130.         if (i != a[i - 1]) {
  131.             cout << "NO";
  132.             return;
  133.         }
  134.     }
  135.     cout << "YES\n" << l + 1;
  136.  
  137. }
  138.  
  139. signed main() {
  140.     ios::sync_with_stdio(false);
  141.     cin.tie(nullptr);
  142.     cout.tie(nullptr);
  143.  
  144.     int T = 1;
  145.     //cin >> T;
  146.     while (T--) {
  147.         solve();
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment