답안 #1014114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1014114 2024-07-04T10:59:36 Z snpmrnhlol Rope (JOI17_rope) C++17
100 / 100
426 ms 33640 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6;
const int inf = 2e9;
int n,k;
int v[N];
int f[N];
int p[N];
int ans[N];
pair<int,int> special[N];
int cnt;
int get(pair<int,int>a){
    int l = 0,r = cnt - 1;
    if(cnt == 0)return 0;
    while(l != r){
        int mij = (l + r)/2;
        if(special[mij] < a)l = mij + 1;
        else r = mij;
    }
    while(r < cnt && special[r] == a){
        r++;
    }
    return r - l;
}
void solve(int l, int r){
    cnt = 0;
    for(int i = l;i < r;i+=2){
        if(v[i] != v[i + 1]){
            special[cnt++] = {min(v[i],v[i + 1]),max(v[i],v[i + 1])};
        }
    }
    sort(special,special + cnt);
    for(int i = 0;i < k;i++){
        for(int j = 0;j < k;j++){
            if(i == p[j])continue;
            int nr = get({min(i,p[j]),max(i,p[j])});
            //cout<<l<<' '<<r<<' '<<i<<' '<<j<<' '<<p[j]<<' '<<n<<' '<<nr<<' '<<n - f[p[j]] - f[i] - nr<<'\n';
            ans[i] = min(ans[i],n - f[p[j]] - f[i] + nr);
            if(nr == 0)break;
        }
    }
}
int main(){
    cin>>n>>k;
    for(int i = 0;i < n;i++){
        cin>>v[i];
        v[i]--;
        f[v[i]]++;
        ans[i] = inf;
        p[i] = i;
    }
    sort(p,p + k,[&](int a,int b){
         return f[a] > f[b];
    });
    if(n%2 == 0){
        solve(0,n - 1);
        if(n >= 2)solve(1,n - 2);
    }else{
        solve(0,n - 2);
        solve(1,n - 1);
    }
    for(int i = 0;i < k;i++){
        ans[i] = min(ans[i],n - f[i]);
        cout<<ans[i]<<'\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 0 ms 2492 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2496 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 0 ms 2492 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2496 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 13 ms 3792 KB Output is correct
28 Correct 15 ms 3764 KB Output is correct
29 Correct 17 ms 3676 KB Output is correct
30 Correct 19 ms 3776 KB Output is correct
31 Correct 13 ms 3676 KB Output is correct
32 Correct 10 ms 3676 KB Output is correct
33 Correct 12 ms 3672 KB Output is correct
34 Correct 10 ms 3676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 0 ms 2492 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2496 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 13 ms 3792 KB Output is correct
28 Correct 15 ms 3764 KB Output is correct
29 Correct 17 ms 3676 KB Output is correct
30 Correct 19 ms 3776 KB Output is correct
31 Correct 13 ms 3676 KB Output is correct
32 Correct 10 ms 3676 KB Output is correct
33 Correct 12 ms 3672 KB Output is correct
34 Correct 10 ms 3676 KB Output is correct
35 Correct 19 ms 3932 KB Output is correct
36 Correct 17 ms 3932 KB Output is correct
37 Correct 24 ms 3932 KB Output is correct
38 Correct 19 ms 3932 KB Output is correct
39 Correct 20 ms 3932 KB Output is correct
40 Correct 21 ms 3932 KB Output is correct
41 Correct 19 ms 5720 KB Output is correct
42 Correct 19 ms 5592 KB Output is correct
43 Correct 18 ms 5464 KB Output is correct
44 Correct 19 ms 5708 KB Output is correct
45 Correct 20 ms 4064 KB Output is correct
46 Correct 19 ms 3932 KB Output is correct
47 Correct 26 ms 3964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 0 ms 2492 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2496 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 13 ms 3792 KB Output is correct
28 Correct 15 ms 3764 KB Output is correct
29 Correct 17 ms 3676 KB Output is correct
30 Correct 19 ms 3776 KB Output is correct
31 Correct 13 ms 3676 KB Output is correct
32 Correct 10 ms 3676 KB Output is correct
33 Correct 12 ms 3672 KB Output is correct
34 Correct 10 ms 3676 KB Output is correct
35 Correct 19 ms 3932 KB Output is correct
36 Correct 17 ms 3932 KB Output is correct
37 Correct 24 ms 3932 KB Output is correct
38 Correct 19 ms 3932 KB Output is correct
39 Correct 20 ms 3932 KB Output is correct
40 Correct 21 ms 3932 KB Output is correct
41 Correct 19 ms 5720 KB Output is correct
42 Correct 19 ms 5592 KB Output is correct
43 Correct 18 ms 5464 KB Output is correct
44 Correct 19 ms 5708 KB Output is correct
45 Correct 20 ms 4064 KB Output is correct
46 Correct 19 ms 3932 KB Output is correct
47 Correct 26 ms 3964 KB Output is correct
48 Correct 222 ms 21332 KB Output is correct
49 Correct 223 ms 21588 KB Output is correct
50 Correct 220 ms 21328 KB Output is correct
51 Correct 213 ms 21192 KB Output is correct
52 Correct 202 ms 20816 KB Output is correct
53 Correct 225 ms 21332 KB Output is correct
54 Correct 234 ms 21372 KB Output is correct
55 Correct 251 ms 22856 KB Output is correct
56 Correct 241 ms 21328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 0 ms 2492 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2496 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 13 ms 3792 KB Output is correct
28 Correct 15 ms 3764 KB Output is correct
29 Correct 17 ms 3676 KB Output is correct
30 Correct 19 ms 3776 KB Output is correct
31 Correct 13 ms 3676 KB Output is correct
32 Correct 10 ms 3676 KB Output is correct
33 Correct 12 ms 3672 KB Output is correct
34 Correct 10 ms 3676 KB Output is correct
35 Correct 19 ms 3932 KB Output is correct
36 Correct 17 ms 3932 KB Output is correct
37 Correct 24 ms 3932 KB Output is correct
38 Correct 19 ms 3932 KB Output is correct
39 Correct 20 ms 3932 KB Output is correct
40 Correct 21 ms 3932 KB Output is correct
41 Correct 19 ms 5720 KB Output is correct
42 Correct 19 ms 5592 KB Output is correct
43 Correct 18 ms 5464 KB Output is correct
44 Correct 19 ms 5708 KB Output is correct
45 Correct 20 ms 4064 KB Output is correct
46 Correct 19 ms 3932 KB Output is correct
47 Correct 26 ms 3964 KB Output is correct
48 Correct 222 ms 21332 KB Output is correct
49 Correct 223 ms 21588 KB Output is correct
50 Correct 220 ms 21328 KB Output is correct
51 Correct 213 ms 21192 KB Output is correct
52 Correct 202 ms 20816 KB Output is correct
53 Correct 225 ms 21332 KB Output is correct
54 Correct 234 ms 21372 KB Output is correct
55 Correct 251 ms 22856 KB Output is correct
56 Correct 241 ms 21328 KB Output is correct
57 Correct 426 ms 33640 KB Output is correct
58 Correct 353 ms 30000 KB Output is correct
59 Correct 349 ms 30036 KB Output is correct
60 Correct 358 ms 31356 KB Output is correct
61 Correct 342 ms 31316 KB Output is correct
62 Correct 322 ms 26616 KB Output is correct
63 Correct 299 ms 27984 KB Output is correct
64 Correct 329 ms 27228 KB Output is correct
65 Correct 288 ms 24772 KB Output is correct