답안 #573409

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
573409 2022-06-06T14:37:04 Z MohammadAghil Money (IZhO17_money) C++14
100 / 100
171 ms 16064 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 8148 KB Output is correct
2 Correct 8 ms 8148 KB Output is correct
3 Correct 9 ms 8148 KB Output is correct
4 Correct 8 ms 8148 KB Output is correct
5 Correct 8 ms 8148 KB Output is correct
6 Correct 8 ms 8148 KB Output is correct
7 Correct 8 ms 8148 KB Output is correct
8 Correct 9 ms 8168 KB Output is correct
9 Correct 7 ms 8148 KB Output is correct
10 Correct 9 ms 8180 KB Output is correct
11 Correct 8 ms 8148 KB Output is correct
12 Correct 8 ms 8180 KB Output is correct
13 Correct 9 ms 8064 KB Output is correct
14 Correct 8 ms 8148 KB Output is correct
15 Correct 8 ms 8184 KB Output is correct
16 Correct 8 ms 8192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8148 KB Output is correct
2 Correct 8 ms 8148 KB Output is correct
3 Correct 9 ms 8148 KB Output is correct
4 Correct 8 ms 8148 KB Output is correct
5 Correct 8 ms 8148 KB Output is correct
6 Correct 8 ms 8148 KB Output is correct
7 Correct 8 ms 8148 KB Output is correct
8 Correct 9 ms 8168 KB Output is correct
9 Correct 7 ms 8148 KB Output is correct
10 Correct 9 ms 8180 KB Output is correct
11 Correct 8 ms 8148 KB Output is correct
12 Correct 8 ms 8180 KB Output is correct
13 Correct 9 ms 8064 KB Output is correct
14 Correct 8 ms 8148 KB Output is correct
15 Correct 8 ms 8184 KB Output is correct
16 Correct 8 ms 8192 KB Output is correct
17 Correct 8 ms 8132 KB Output is correct
18 Correct 8 ms 8148 KB Output is correct
19 Correct 9 ms 8148 KB Output is correct
20 Correct 9 ms 8184 KB Output is correct
21 Correct 8 ms 8148 KB Output is correct
22 Correct 8 ms 8176 KB Output is correct
23 Correct 9 ms 8176 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 8148 KB Output is correct
2 Correct 8 ms 8148 KB Output is correct
3 Correct 9 ms 8148 KB Output is correct
4 Correct 8 ms 8148 KB Output is correct
5 Correct 8 ms 8148 KB Output is correct
6 Correct 8 ms 8148 KB Output is correct
7 Correct 8 ms 8148 KB Output is correct
8 Correct 9 ms 8168 KB Output is correct
9 Correct 7 ms 8148 KB Output is correct
10 Correct 9 ms 8180 KB Output is correct
11 Correct 8 ms 8148 KB Output is correct
12 Correct 8 ms 8180 KB Output is correct
13 Correct 9 ms 8064 KB Output is correct
14 Correct 8 ms 8148 KB Output is correct
15 Correct 8 ms 8184 KB Output is correct
16 Correct 8 ms 8192 KB Output is correct
17 Correct 8 ms 8132 KB Output is correct
18 Correct 8 ms 8148 KB Output is correct
19 Correct 9 ms 8148 KB Output is correct
20 Correct 9 ms 8184 KB Output is correct
21 Correct 8 ms 8148 KB Output is correct
22 Correct 8 ms 8176 KB Output is correct
23 Correct 9 ms 8176 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 7 ms 8148 KB Output is correct
29 Correct 8 ms 8164 KB Output is correct
30 Correct 8 ms 8148 KB Output is correct
31 Correct 8 ms 8164 KB Output is correct
32 Correct 9 ms 8148 KB Output is correct
33 Correct 8 ms 8188 KB Output is correct
34 Correct 8 ms 8148 KB Output is correct
35 Correct 8 ms 8180 KB Output is correct
36 Correct 8 ms 8148 KB Output is correct
37 Correct 8 ms 8660 KB Output is correct
38 Correct 8 ms 8760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 8148 KB Output is correct
2 Correct 8 ms 8148 KB Output is correct
3 Correct 9 ms 8148 KB Output is correct
4 Correct 8 ms 8148 KB Output is correct
5 Correct 8 ms 8148 KB Output is correct
6 Correct 8 ms 8148 KB Output is correct
7 Correct 8 ms 8148 KB Output is correct
8 Correct 9 ms 8168 KB Output is correct
9 Correct 7 ms 8148 KB Output is correct
10 Correct 9 ms 8180 KB Output is correct
11 Correct 8 ms 8148 KB Output is correct
12 Correct 8 ms 8180 KB Output is correct
13 Correct 9 ms 8064 KB Output is correct
14 Correct 8 ms 8148 KB Output is correct
15 Correct 8 ms 8184 KB Output is correct
16 Correct 8 ms 8192 KB Output is correct
17 Correct 8 ms 8132 KB Output is correct
18 Correct 8 ms 8148 KB Output is correct
19 Correct 9 ms 8148 KB Output is correct
20 Correct 9 ms 8184 KB Output is correct
21 Correct 8 ms 8148 KB Output is correct
22 Correct 8 ms 8176 KB Output is correct
23 Correct 9 ms 8176 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 7 ms 8148 KB Output is correct
29 Correct 8 ms 8164 KB Output is correct
30 Correct 8 ms 8148 KB Output is correct
31 Correct 8 ms 8164 KB Output is correct
32 Correct 9 ms 8148 KB Output is correct
33 Correct 8 ms 8188 KB Output is correct
34 Correct 8 ms 8148 KB Output is correct
35 Correct 8 ms 8180 KB Output is correct
36 Correct 8 ms 8148 KB Output is correct
37 Correct 8 ms 8660 KB Output is correct
38 Correct 8 ms 8760 KB Output is correct
39 Correct 48 ms 10048 KB Output is correct
40 Correct 70 ms 11212 KB Output is correct
41 Correct 39 ms 9676 KB Output is correct
42 Correct 35 ms 9560 KB Output is correct
43 Correct 28 ms 9164 KB Output is correct
44 Correct 85 ms 12100 KB Output is correct
45 Correct 87 ms 11980 KB Output is correct
46 Correct 86 ms 12096 KB Output is correct
47 Correct 87 ms 12060 KB Output is correct
48 Correct 88 ms 12068 KB Output is correct
49 Correct 126 ms 15924 KB Output is correct
50 Correct 130 ms 15956 KB Output is correct
51 Correct 133 ms 16064 KB Output is correct
52 Correct 130 ms 15976 KB Output is correct
53 Correct 127 ms 15928 KB Output is correct
54 Correct 133 ms 15924 KB Output is correct
55 Correct 171 ms 15948 KB Output is correct
56 Correct 165 ms 15908 KB Output is correct
57 Correct 170 ms 15948 KB Output is correct
58 Correct 156 ms 15960 KB Output is correct
59 Correct 159 ms 15972 KB Output is correct
60 Correct 163 ms 15964 KB Output is correct
61 Correct 155 ms 15948 KB Output is correct
62 Correct 157 ms 15956 KB Output is correct