답안 #573407

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
573407 2022-06-06T14:36:14 Z MohammadAghil Money (IZhO17_money) C++14
100 / 100
178 ms 22616 KB
      #include <bits/stdc++.h>
  #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
    using namespace std;
  typedef long long ll;
   typedef pair<int, int> pp;
    #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
      #define per(i,r,l) for(int i = (r); i >= (l); i--)
        #define rep(i,l,r) for(int i = (l); i < (r); i++)
           #define all(x) x.begin(), x.end()
              #define sz(x) (int)(x).size()
                  #define pb push_back
                      #define ss second
                           #define ff first
                                   void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 1e6 + 5, lg = 22, lng = 26, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}

int prv[maxn], nxt[maxn], cnt[maxn];

void del(int x){
     prv[nxt[x]] = prv[x], nxt[prv[x]] = nxt[x];
}

int main(){
     cin.tie(0) -> sync_with_stdio(0);
     int n; cin >> n;
     vector<int> a(n);
     rep(i,0,n) cin >> a[i], cnt[a[i]]++;
     iota(nxt, nxt + maxn, 1), iota(prv, prv + maxn, -1);
     rep(i,1,maxn-1) if(!cnt[i]) del(i);
     int ans = 0, bl = 0;
     per(i,n-1,0){
          if(i == n-1 || (bl > 1 && a[i] - a[i+1] && cnt[a[i+1]]) || (a[i] - a[i+1] && prv[a[i+1]] - a[i])) bl = 0, ans++;
          if(i == n-1 || a[i] - a[i+1]) bl++;
          cnt[a[i]]--;
          if(!cnt[a[i]]) del(a[i]);
     }
     cout << ans << '\n';
     return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8156 KB Output is correct
2 Correct 8 ms 8148 KB Output is correct
3 Correct 8 ms 8160 KB Output is correct
4 Correct 9 ms 8048 KB Output is correct
5 Correct 8 ms 8160 KB Output is correct
6 Correct 8 ms 8148 KB Output is correct
7 Correct 8 ms 8132 KB Output is correct
8 Correct 9 ms 8148 KB Output is correct
9 Correct 8 ms 8148 KB Output is correct
10 Correct 8 ms 8148 KB Output is correct
11 Correct 8 ms 8148 KB Output is correct
12 Correct 7 ms 8148 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 9 ms 8148 KB Output is correct
15 Correct 8 ms 8192 KB Output is correct
16 Correct 8 ms 8148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8156 KB Output is correct
2 Correct 8 ms 8148 KB Output is correct
3 Correct 8 ms 8160 KB Output is correct
4 Correct 9 ms 8048 KB Output is correct
5 Correct 8 ms 8160 KB Output is correct
6 Correct 8 ms 8148 KB Output is correct
7 Correct 8 ms 8132 KB Output is correct
8 Correct 9 ms 8148 KB Output is correct
9 Correct 8 ms 8148 KB Output is correct
10 Correct 8 ms 8148 KB Output is correct
11 Correct 8 ms 8148 KB Output is correct
12 Correct 7 ms 8148 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 9 ms 8148 KB Output is correct
15 Correct 8 ms 8192 KB Output is correct
16 Correct 8 ms 8148 KB Output is correct
17 Correct 8 ms 8120 KB Output is correct
18 Correct 8 ms 8148 KB Output is correct
19 Correct 8 ms 8180 KB Output is correct
20 Correct 8 ms 8148 KB Output is correct
21 Correct 8 ms 8148 KB Output is correct
22 Correct 8 ms 8172 KB Output is correct
23 Correct 8 ms 8148 KB Output is correct
24 Correct 8 ms 8148 KB Output is correct
25 Correct 8 ms 8148 KB Output is correct
26 Correct 8 ms 8148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8156 KB Output is correct
2 Correct 8 ms 8148 KB Output is correct
3 Correct 8 ms 8160 KB Output is correct
4 Correct 9 ms 8048 KB Output is correct
5 Correct 8 ms 8160 KB Output is correct
6 Correct 8 ms 8148 KB Output is correct
7 Correct 8 ms 8132 KB Output is correct
8 Correct 9 ms 8148 KB Output is correct
9 Correct 8 ms 8148 KB Output is correct
10 Correct 8 ms 8148 KB Output is correct
11 Correct 8 ms 8148 KB Output is correct
12 Correct 7 ms 8148 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 9 ms 8148 KB Output is correct
15 Correct 8 ms 8192 KB Output is correct
16 Correct 8 ms 8148 KB Output is correct
17 Correct 8 ms 8120 KB Output is correct
18 Correct 8 ms 8148 KB Output is correct
19 Correct 8 ms 8180 KB Output is correct
20 Correct 8 ms 8148 KB Output is correct
21 Correct 8 ms 8148 KB Output is correct
22 Correct 8 ms 8172 KB Output is correct
23 Correct 8 ms 8148 KB Output is correct
24 Correct 8 ms 8148 KB Output is correct
25 Correct 8 ms 8148 KB Output is correct
26 Correct 8 ms 8148 KB Output is correct
27 Correct 8 ms 8148 KB Output is correct
28 Correct 8 ms 8148 KB Output is correct
29 Correct 8 ms 8132 KB Output is correct
30 Correct 8 ms 8164 KB Output is correct
31 Correct 9 ms 8160 KB Output is correct
32 Correct 8 ms 8148 KB Output is correct
33 Correct 8 ms 8148 KB Output is correct
34 Correct 9 ms 8148 KB Output is correct
35 Correct 9 ms 8148 KB Output is correct
36 Correct 8 ms 8148 KB Output is correct
37 Correct 8 ms 8604 KB Output is correct
38 Correct 9 ms 8660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8156 KB Output is correct
2 Correct 8 ms 8148 KB Output is correct
3 Correct 8 ms 8160 KB Output is correct
4 Correct 9 ms 8048 KB Output is correct
5 Correct 8 ms 8160 KB Output is correct
6 Correct 8 ms 8148 KB Output is correct
7 Correct 8 ms 8132 KB Output is correct
8 Correct 9 ms 8148 KB Output is correct
9 Correct 8 ms 8148 KB Output is correct
10 Correct 8 ms 8148 KB Output is correct
11 Correct 8 ms 8148 KB Output is correct
12 Correct 7 ms 8148 KB Output is correct
13 Correct 8 ms 8172 KB Output is correct
14 Correct 9 ms 8148 KB Output is correct
15 Correct 8 ms 8192 KB Output is correct
16 Correct 8 ms 8148 KB Output is correct
17 Correct 8 ms 8120 KB Output is correct
18 Correct 8 ms 8148 KB Output is correct
19 Correct 8 ms 8180 KB Output is correct
20 Correct 8 ms 8148 KB Output is correct
21 Correct 8 ms 8148 KB Output is correct
22 Correct 8 ms 8172 KB Output is correct
23 Correct 8 ms 8148 KB Output is correct
24 Correct 8 ms 8148 KB Output is correct
25 Correct 8 ms 8148 KB Output is correct
26 Correct 8 ms 8148 KB Output is correct
27 Correct 8 ms 8148 KB Output is correct
28 Correct 8 ms 8148 KB Output is correct
29 Correct 8 ms 8132 KB Output is correct
30 Correct 8 ms 8164 KB Output is correct
31 Correct 9 ms 8160 KB Output is correct
32 Correct 8 ms 8148 KB Output is correct
33 Correct 8 ms 8148 KB Output is correct
34 Correct 9 ms 8148 KB Output is correct
35 Correct 9 ms 8148 KB Output is correct
36 Correct 8 ms 8148 KB Output is correct
37 Correct 8 ms 8604 KB Output is correct
38 Correct 9 ms 8660 KB Output is correct
39 Correct 50 ms 10052 KB Output is correct
40 Correct 72 ms 11276 KB Output is correct
41 Correct 39 ms 9692 KB Output is correct
42 Correct 35 ms 9540 KB Output is correct
43 Correct 31 ms 9164 KB Output is correct
44 Correct 92 ms 12092 KB Output is correct
45 Correct 86 ms 12096 KB Output is correct
46 Correct 86 ms 12088 KB Output is correct
47 Correct 89 ms 12060 KB Output is correct
48 Correct 93 ms 12080 KB Output is correct
49 Correct 130 ms 15872 KB Output is correct
50 Correct 137 ms 16032 KB Output is correct
51 Correct 133 ms 15960 KB Output is correct
52 Correct 128 ms 15908 KB Output is correct
53 Correct 127 ms 15900 KB Output is correct
54 Correct 134 ms 15948 KB Output is correct
55 Correct 173 ms 15960 KB Output is correct
56 Correct 169 ms 15960 KB Output is correct
57 Correct 174 ms 22608 KB Output is correct
58 Correct 174 ms 22604 KB Output is correct
59 Correct 171 ms 22612 KB Output is correct
60 Correct 154 ms 22596 KB Output is correct
61 Correct 167 ms 22616 KB Output is correct
62 Correct 178 ms 22600 KB Output is correct