답안 #665887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
665887 2022-11-27T13:58:11 Z Astrayt Money (IZhO17_money) C++17
100 / 100
221 ms 43468 KB
//君の手を握ってしまったら
//孤独を知らないこの街には
//もう二度と帰ってくることはできないのでしょう
//君が手を差し伸べた 光で影が生まれる
//歌って聞かせて この話の続き
//連れて行って見たことない星まで
//さユリ - 花の塔
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define starburst ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pii pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define maxn 1000005
#define mod 1000000007

struct DisjointSetUnion{
    int par[maxn];
    void init(){
        for(int i = 1; i <= maxn - 1; ++i) par[i] = i;
    }
    int qry(int u){
        return (u == par[u] ? u : par[u] = qry(par[u]));
    }
    void uni(int u, int v){
        u = qry(u), v = qry(v);
        par[u] = v;
    }
}dsu;

void solve(){
    int n, ans = 0; cin >> n;
    vector<int> v(n), cnt(maxn, 0);
    for(auto &x:v) cin >> x, cnt[x]++;
    dsu.init();
    for(int i = maxn - 1; i >= 1; --i) if(cnt[i] == 0) dsu.uni(i, i - 1);
    for(int i = n - 1, j = n - 1; i >= 0; i = j){
        ans++;
        while(j >= 0 && v[i] == v[j]) cnt[v[j]]--, j--;
        if(cnt[v[i]] == 0) dsu.uni(v[i], v[i] - 1);
        int x = dsu.qry(v[i] - 1);
        while(j >= 0){
            if(x != v[j]) break;
            cnt[v[j]]--, j--;
            if(cnt[x] == 0){
                dsu.uni(x, x - 1);
                x = dsu.qry(x);
            }
        }
    }
    cout << ans << '\n';
}

signed main(){
    starburst
    int t = 1; //cin >> t;
    while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15984 KB Output is correct
2 Correct 9 ms 15860 KB Output is correct
3 Correct 9 ms 15956 KB Output is correct
4 Correct 9 ms 15860 KB Output is correct
5 Correct 9 ms 15956 KB Output is correct
6 Correct 8 ms 15956 KB Output is correct
7 Correct 14 ms 20720 KB Output is correct
8 Correct 17 ms 27220 KB Output is correct
9 Correct 13 ms 22376 KB Output is correct
10 Correct 14 ms 20308 KB Output is correct
11 Correct 15 ms 25056 KB Output is correct
12 Correct 13 ms 20820 KB Output is correct
13 Correct 16 ms 25092 KB Output is correct
14 Correct 14 ms 23624 KB Output is correct
15 Correct 15 ms 21588 KB Output is correct
16 Correct 15 ms 21492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15984 KB Output is correct
2 Correct 9 ms 15860 KB Output is correct
3 Correct 9 ms 15956 KB Output is correct
4 Correct 9 ms 15860 KB Output is correct
5 Correct 9 ms 15956 KB Output is correct
6 Correct 8 ms 15956 KB Output is correct
7 Correct 14 ms 20720 KB Output is correct
8 Correct 17 ms 27220 KB Output is correct
9 Correct 13 ms 22376 KB Output is correct
10 Correct 14 ms 20308 KB Output is correct
11 Correct 15 ms 25056 KB Output is correct
12 Correct 13 ms 20820 KB Output is correct
13 Correct 16 ms 25092 KB Output is correct
14 Correct 14 ms 23624 KB Output is correct
15 Correct 15 ms 21588 KB Output is correct
16 Correct 15 ms 21492 KB Output is correct
17 Correct 17 ms 21972 KB Output is correct
18 Correct 15 ms 22800 KB Output is correct
19 Correct 13 ms 19912 KB Output is correct
20 Correct 17 ms 23360 KB Output is correct
21 Correct 12 ms 19508 KB Output is correct
22 Correct 17 ms 23884 KB Output is correct
23 Correct 16 ms 26052 KB Output is correct
24 Correct 20 ms 21496 KB Output is correct
25 Correct 15 ms 19960 KB Output is correct
26 Correct 15 ms 20296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15984 KB Output is correct
2 Correct 9 ms 15860 KB Output is correct
3 Correct 9 ms 15956 KB Output is correct
4 Correct 9 ms 15860 KB Output is correct
5 Correct 9 ms 15956 KB Output is correct
6 Correct 8 ms 15956 KB Output is correct
7 Correct 14 ms 20720 KB Output is correct
8 Correct 17 ms 27220 KB Output is correct
9 Correct 13 ms 22376 KB Output is correct
10 Correct 14 ms 20308 KB Output is correct
11 Correct 15 ms 25056 KB Output is correct
12 Correct 13 ms 20820 KB Output is correct
13 Correct 16 ms 25092 KB Output is correct
14 Correct 14 ms 23624 KB Output is correct
15 Correct 15 ms 21588 KB Output is correct
16 Correct 15 ms 21492 KB Output is correct
17 Correct 17 ms 21972 KB Output is correct
18 Correct 15 ms 22800 KB Output is correct
19 Correct 13 ms 19912 KB Output is correct
20 Correct 17 ms 23360 KB Output is correct
21 Correct 12 ms 19508 KB Output is correct
22 Correct 17 ms 23884 KB Output is correct
23 Correct 16 ms 26052 KB Output is correct
24 Correct 20 ms 21496 KB Output is correct
25 Correct 15 ms 19960 KB Output is correct
26 Correct 15 ms 20296 KB Output is correct
27 Correct 11 ms 15956 KB Output is correct
28 Correct 8 ms 15956 KB Output is correct
29 Correct 10 ms 15956 KB Output is correct
30 Correct 11 ms 15956 KB Output is correct
31 Correct 10 ms 15944 KB Output is correct
32 Correct 14 ms 21244 KB Output is correct
33 Correct 14 ms 20564 KB Output is correct
34 Correct 15 ms 20552 KB Output is correct
35 Correct 14 ms 21864 KB Output is correct
36 Correct 15 ms 24404 KB Output is correct
37 Correct 12 ms 16468 KB Output is correct
38 Correct 12 ms 16852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15984 KB Output is correct
2 Correct 9 ms 15860 KB Output is correct
3 Correct 9 ms 15956 KB Output is correct
4 Correct 9 ms 15860 KB Output is correct
5 Correct 9 ms 15956 KB Output is correct
6 Correct 8 ms 15956 KB Output is correct
7 Correct 14 ms 20720 KB Output is correct
8 Correct 17 ms 27220 KB Output is correct
9 Correct 13 ms 22376 KB Output is correct
10 Correct 14 ms 20308 KB Output is correct
11 Correct 15 ms 25056 KB Output is correct
12 Correct 13 ms 20820 KB Output is correct
13 Correct 16 ms 25092 KB Output is correct
14 Correct 14 ms 23624 KB Output is correct
15 Correct 15 ms 21588 KB Output is correct
16 Correct 15 ms 21492 KB Output is correct
17 Correct 17 ms 21972 KB Output is correct
18 Correct 15 ms 22800 KB Output is correct
19 Correct 13 ms 19912 KB Output is correct
20 Correct 17 ms 23360 KB Output is correct
21 Correct 12 ms 19508 KB Output is correct
22 Correct 17 ms 23884 KB Output is correct
23 Correct 16 ms 26052 KB Output is correct
24 Correct 20 ms 21496 KB Output is correct
25 Correct 15 ms 19960 KB Output is correct
26 Correct 15 ms 20296 KB Output is correct
27 Correct 11 ms 15956 KB Output is correct
28 Correct 8 ms 15956 KB Output is correct
29 Correct 10 ms 15956 KB Output is correct
30 Correct 11 ms 15956 KB Output is correct
31 Correct 10 ms 15944 KB Output is correct
32 Correct 14 ms 21244 KB Output is correct
33 Correct 14 ms 20564 KB Output is correct
34 Correct 15 ms 20552 KB Output is correct
35 Correct 14 ms 21864 KB Output is correct
36 Correct 15 ms 24404 KB Output is correct
37 Correct 12 ms 16468 KB Output is correct
38 Correct 12 ms 16852 KB Output is correct
39 Correct 65 ms 31104 KB Output is correct
40 Correct 151 ms 33100 KB Output is correct
41 Correct 50 ms 31280 KB Output is correct
42 Correct 46 ms 23892 KB Output is correct
43 Correct 33 ms 22212 KB Output is correct
44 Correct 103 ms 34408 KB Output is correct
45 Correct 127 ms 36304 KB Output is correct
46 Correct 138 ms 35524 KB Output is correct
47 Correct 128 ms 43468 KB Output is correct
48 Correct 110 ms 37864 KB Output is correct
49 Correct 211 ms 30608 KB Output is correct
50 Correct 171 ms 30564 KB Output is correct
51 Correct 199 ms 30440 KB Output is correct
52 Correct 197 ms 30596 KB Output is correct
53 Correct 170 ms 30604 KB Output is correct
54 Correct 170 ms 30312 KB Output is correct
55 Correct 213 ms 30652 KB Output is correct
56 Correct 221 ms 30544 KB Output is correct
57 Correct 219 ms 30432 KB Output is correct
58 Correct 209 ms 30436 KB Output is correct
59 Correct 195 ms 30540 KB Output is correct
60 Correct 200 ms 30428 KB Output is correct
61 Correct 204 ms 30432 KB Output is correct
62 Correct 198 ms 30548 KB Output is correct