# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
299457 | 2020-09-14T23:46:22 Z | XmtosX | Rope (JOI17_rope) | C++17 | 2500 ms | 124408 KB |
#include <bits/stdc++.h> using namespace std; const int N=1e6+5; int n,m,a[N],cnt[N],ans[N],cnt1[N]; bool yes; vector <int> v[N],V; set<long long > s; long long mul (long long x,int y) { x*=10000000ll; x+=y; return x; } int main() { scanf("%d%d",&n,&m); for (int i=0;i<n;i++) { scanf("%d",&a[i]); cnt[a[i]]++; cnt1[a[i]]++; ans[a[i]]=n-cnt[i]; } for (int i=1;i<=m;i++) s.insert(mul(cnt[i],i)); for (int o=0;o<2;o++) { for (int i=1;i<=m;i++) v[i].clear(); if ((n-o)%2) yes=true; else yes=false; for (int i=o;i+1<n;i+=2) { v[a[i]].push_back(i); if (a[i]!=a[i+1]) v[a[i+1]].push_back(i); } for (int i=1;i<=m;i++) { V.clear(); int tot=n; if (o&&a[0]==i) { cnt1[i]--; V.push_back(i); tot--; } for (int j=0;j<v[i].size();j++) { int idx= v[i][j]; if (cnt1[a[idx]]==cnt[a[idx]]) V.push_back(a[idx]); cnt1[a[idx]]--; tot-=(a[idx]==i); idx++; if (cnt1[a[idx]]==cnt[a[idx]]) V.push_back(a[idx]); cnt1[a[idx]]--; tot-=(a[idx]==i); } if (yes&&a[n-1]==i) { cnt1[i]--; if (cnt[i]==cnt1[i]) V.push_back(i); tot--; } for (int j=0;j<V.size();j++) { s.erase(mul(cnt[V[j]],V[j])); s.insert(mul(cnt1[V[j]],V[j])); } long long p = *s.rbegin(); p/=10000000ll; ans[i]=min(ans[i],(int)(tot-p)); for (int j=0;j<V.size();j++) { s.erase(mul(cnt1[V[j]],V[j])); s.insert(mul(cnt[V[j]],V[j])); cnt1[V[j]]=cnt[V[j]]; } } } for (int i=1;i<=m;i++) printf("%d\n",ans[i]); return 0; } /* 5 3 1 2 3 3 2 7 3 1 2 2 1 3 3 3 10 3 2 2 1 1 3 3 2 1 1 2 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23808 KB | Output is correct |
2 | Correct | 18 ms | 23808 KB | Output is correct |
3 | Correct | 17 ms | 23840 KB | Output is correct |
4 | Correct | 18 ms | 23808 KB | Output is correct |
5 | Correct | 16 ms | 23808 KB | Output is correct |
6 | Correct | 17 ms | 23808 KB | Output is correct |
7 | Correct | 17 ms | 23808 KB | Output is correct |
8 | Correct | 16 ms | 23808 KB | Output is correct |
9 | Correct | 16 ms | 23808 KB | Output is correct |
10 | Correct | 16 ms | 23808 KB | Output is correct |
11 | Correct | 16 ms | 23808 KB | Output is correct |
12 | Correct | 16 ms | 23808 KB | Output is correct |
13 | Correct | 17 ms | 23808 KB | Output is correct |
14 | Correct | 16 ms | 23808 KB | Output is correct |
15 | Correct | 17 ms | 23840 KB | Output is correct |
16 | Correct | 17 ms | 23808 KB | Output is correct |
17 | Correct | 16 ms | 23808 KB | Output is correct |
18 | Correct | 16 ms | 23808 KB | Output is correct |
19 | Correct | 16 ms | 23808 KB | Output is correct |
20 | Correct | 16 ms | 23808 KB | Output is correct |
21 | Correct | 17 ms | 23936 KB | Output is correct |
22 | Correct | 16 ms | 23808 KB | Output is correct |
23 | Correct | 17 ms | 23808 KB | Output is correct |
24 | Correct | 17 ms | 23808 KB | Output is correct |
25 | Correct | 16 ms | 23808 KB | Output is correct |
26 | Correct | 17 ms | 23808 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23808 KB | Output is correct |
2 | Correct | 18 ms | 23808 KB | Output is correct |
3 | Correct | 17 ms | 23840 KB | Output is correct |
4 | Correct | 18 ms | 23808 KB | Output is correct |
5 | Correct | 16 ms | 23808 KB | Output is correct |
6 | Correct | 17 ms | 23808 KB | Output is correct |
7 | Correct | 17 ms | 23808 KB | Output is correct |
8 | Correct | 16 ms | 23808 KB | Output is correct |
9 | Correct | 16 ms | 23808 KB | Output is correct |
10 | Correct | 16 ms | 23808 KB | Output is correct |
11 | Correct | 16 ms | 23808 KB | Output is correct |
12 | Correct | 16 ms | 23808 KB | Output is correct |
13 | Correct | 17 ms | 23808 KB | Output is correct |
14 | Correct | 16 ms | 23808 KB | Output is correct |
15 | Correct | 17 ms | 23840 KB | Output is correct |
16 | Correct | 17 ms | 23808 KB | Output is correct |
17 | Correct | 16 ms | 23808 KB | Output is correct |
18 | Correct | 16 ms | 23808 KB | Output is correct |
19 | Correct | 16 ms | 23808 KB | Output is correct |
20 | Correct | 16 ms | 23808 KB | Output is correct |
21 | Correct | 17 ms | 23936 KB | Output is correct |
22 | Correct | 16 ms | 23808 KB | Output is correct |
23 | Correct | 17 ms | 23808 KB | Output is correct |
24 | Correct | 17 ms | 23808 KB | Output is correct |
25 | Correct | 16 ms | 23808 KB | Output is correct |
26 | Correct | 17 ms | 23808 KB | Output is correct |
27 | Correct | 33 ms | 25084 KB | Output is correct |
28 | Correct | 31 ms | 24960 KB | Output is correct |
29 | Correct | 30 ms | 24960 KB | Output is correct |
30 | Correct | 33 ms | 25088 KB | Output is correct |
31 | Correct | 32 ms | 25080 KB | Output is correct |
32 | Correct | 31 ms | 25080 KB | Output is correct |
33 | Correct | 33 ms | 25088 KB | Output is correct |
34 | Correct | 31 ms | 25088 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23808 KB | Output is correct |
2 | Correct | 18 ms | 23808 KB | Output is correct |
3 | Correct | 17 ms | 23840 KB | Output is correct |
4 | Correct | 18 ms | 23808 KB | Output is correct |
5 | Correct | 16 ms | 23808 KB | Output is correct |
6 | Correct | 17 ms | 23808 KB | Output is correct |
7 | Correct | 17 ms | 23808 KB | Output is correct |
8 | Correct | 16 ms | 23808 KB | Output is correct |
9 | Correct | 16 ms | 23808 KB | Output is correct |
10 | Correct | 16 ms | 23808 KB | Output is correct |
11 | Correct | 16 ms | 23808 KB | Output is correct |
12 | Correct | 16 ms | 23808 KB | Output is correct |
13 | Correct | 17 ms | 23808 KB | Output is correct |
14 | Correct | 16 ms | 23808 KB | Output is correct |
15 | Correct | 17 ms | 23840 KB | Output is correct |
16 | Correct | 17 ms | 23808 KB | Output is correct |
17 | Correct | 16 ms | 23808 KB | Output is correct |
18 | Correct | 16 ms | 23808 KB | Output is correct |
19 | Correct | 16 ms | 23808 KB | Output is correct |
20 | Correct | 16 ms | 23808 KB | Output is correct |
21 | Correct | 17 ms | 23936 KB | Output is correct |
22 | Correct | 16 ms | 23808 KB | Output is correct |
23 | Correct | 17 ms | 23808 KB | Output is correct |
24 | Correct | 17 ms | 23808 KB | Output is correct |
25 | Correct | 16 ms | 23808 KB | Output is correct |
26 | Correct | 17 ms | 23808 KB | Output is correct |
27 | Correct | 33 ms | 25084 KB | Output is correct |
28 | Correct | 31 ms | 24960 KB | Output is correct |
29 | Correct | 30 ms | 24960 KB | Output is correct |
30 | Correct | 33 ms | 25088 KB | Output is correct |
31 | Correct | 32 ms | 25080 KB | Output is correct |
32 | Correct | 31 ms | 25080 KB | Output is correct |
33 | Correct | 33 ms | 25088 KB | Output is correct |
34 | Correct | 31 ms | 25088 KB | Output is correct |
35 | Correct | 124 ms | 25244 KB | Output is correct |
36 | Correct | 127 ms | 25124 KB | Output is correct |
37 | Correct | 125 ms | 25340 KB | Output is correct |
38 | Correct | 122 ms | 25208 KB | Output is correct |
39 | Correct | 126 ms | 25336 KB | Output is correct |
40 | Correct | 80 ms | 25208 KB | Output is correct |
41 | Correct | 79 ms | 25336 KB | Output is correct |
42 | Correct | 70 ms | 25336 KB | Output is correct |
43 | Correct | 66 ms | 25208 KB | Output is correct |
44 | Correct | 82 ms | 25336 KB | Output is correct |
45 | Correct | 80 ms | 25216 KB | Output is correct |
46 | Correct | 71 ms | 25216 KB | Output is correct |
47 | Correct | 68 ms | 25208 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23808 KB | Output is correct |
2 | Correct | 18 ms | 23808 KB | Output is correct |
3 | Correct | 17 ms | 23840 KB | Output is correct |
4 | Correct | 18 ms | 23808 KB | Output is correct |
5 | Correct | 16 ms | 23808 KB | Output is correct |
6 | Correct | 17 ms | 23808 KB | Output is correct |
7 | Correct | 17 ms | 23808 KB | Output is correct |
8 | Correct | 16 ms | 23808 KB | Output is correct |
9 | Correct | 16 ms | 23808 KB | Output is correct |
10 | Correct | 16 ms | 23808 KB | Output is correct |
11 | Correct | 16 ms | 23808 KB | Output is correct |
12 | Correct | 16 ms | 23808 KB | Output is correct |
13 | Correct | 17 ms | 23808 KB | Output is correct |
14 | Correct | 16 ms | 23808 KB | Output is correct |
15 | Correct | 17 ms | 23840 KB | Output is correct |
16 | Correct | 17 ms | 23808 KB | Output is correct |
17 | Correct | 16 ms | 23808 KB | Output is correct |
18 | Correct | 16 ms | 23808 KB | Output is correct |
19 | Correct | 16 ms | 23808 KB | Output is correct |
20 | Correct | 16 ms | 23808 KB | Output is correct |
21 | Correct | 17 ms | 23936 KB | Output is correct |
22 | Correct | 16 ms | 23808 KB | Output is correct |
23 | Correct | 17 ms | 23808 KB | Output is correct |
24 | Correct | 17 ms | 23808 KB | Output is correct |
25 | Correct | 16 ms | 23808 KB | Output is correct |
26 | Correct | 17 ms | 23808 KB | Output is correct |
27 | Correct | 33 ms | 25084 KB | Output is correct |
28 | Correct | 31 ms | 24960 KB | Output is correct |
29 | Correct | 30 ms | 24960 KB | Output is correct |
30 | Correct | 33 ms | 25088 KB | Output is correct |
31 | Correct | 32 ms | 25080 KB | Output is correct |
32 | Correct | 31 ms | 25080 KB | Output is correct |
33 | Correct | 33 ms | 25088 KB | Output is correct |
34 | Correct | 31 ms | 25088 KB | Output is correct |
35 | Correct | 124 ms | 25244 KB | Output is correct |
36 | Correct | 127 ms | 25124 KB | Output is correct |
37 | Correct | 125 ms | 25340 KB | Output is correct |
38 | Correct | 122 ms | 25208 KB | Output is correct |
39 | Correct | 126 ms | 25336 KB | Output is correct |
40 | Correct | 80 ms | 25208 KB | Output is correct |
41 | Correct | 79 ms | 25336 KB | Output is correct |
42 | Correct | 70 ms | 25336 KB | Output is correct |
43 | Correct | 66 ms | 25208 KB | Output is correct |
44 | Correct | 82 ms | 25336 KB | Output is correct |
45 | Correct | 80 ms | 25216 KB | Output is correct |
46 | Correct | 71 ms | 25216 KB | Output is correct |
47 | Correct | 68 ms | 25208 KB | Output is correct |
48 | Correct | 1582 ms | 39160 KB | Output is correct |
49 | Correct | 1590 ms | 39256 KB | Output is correct |
50 | Correct | 1586 ms | 39320 KB | Output is correct |
51 | Correct | 1317 ms | 38648 KB | Output is correct |
52 | Correct | 1062 ms | 37636 KB | Output is correct |
53 | Correct | 873 ms | 38392 KB | Output is correct |
54 | Correct | 667 ms | 37300 KB | Output is correct |
55 | Correct | 662 ms | 37132 KB | Output is correct |
56 | Correct | 574 ms | 36856 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 23808 KB | Output is correct |
2 | Correct | 18 ms | 23808 KB | Output is correct |
3 | Correct | 17 ms | 23840 KB | Output is correct |
4 | Correct | 18 ms | 23808 KB | Output is correct |
5 | Correct | 16 ms | 23808 KB | Output is correct |
6 | Correct | 17 ms | 23808 KB | Output is correct |
7 | Correct | 17 ms | 23808 KB | Output is correct |
8 | Correct | 16 ms | 23808 KB | Output is correct |
9 | Correct | 16 ms | 23808 KB | Output is correct |
10 | Correct | 16 ms | 23808 KB | Output is correct |
11 | Correct | 16 ms | 23808 KB | Output is correct |
12 | Correct | 16 ms | 23808 KB | Output is correct |
13 | Correct | 17 ms | 23808 KB | Output is correct |
14 | Correct | 16 ms | 23808 KB | Output is correct |
15 | Correct | 17 ms | 23840 KB | Output is correct |
16 | Correct | 17 ms | 23808 KB | Output is correct |
17 | Correct | 16 ms | 23808 KB | Output is correct |
18 | Correct | 16 ms | 23808 KB | Output is correct |
19 | Correct | 16 ms | 23808 KB | Output is correct |
20 | Correct | 16 ms | 23808 KB | Output is correct |
21 | Correct | 17 ms | 23936 KB | Output is correct |
22 | Correct | 16 ms | 23808 KB | Output is correct |
23 | Correct | 17 ms | 23808 KB | Output is correct |
24 | Correct | 17 ms | 23808 KB | Output is correct |
25 | Correct | 16 ms | 23808 KB | Output is correct |
26 | Correct | 17 ms | 23808 KB | Output is correct |
27 | Correct | 33 ms | 25084 KB | Output is correct |
28 | Correct | 31 ms | 24960 KB | Output is correct |
29 | Correct | 30 ms | 24960 KB | Output is correct |
30 | Correct | 33 ms | 25088 KB | Output is correct |
31 | Correct | 32 ms | 25080 KB | Output is correct |
32 | Correct | 31 ms | 25080 KB | Output is correct |
33 | Correct | 33 ms | 25088 KB | Output is correct |
34 | Correct | 31 ms | 25088 KB | Output is correct |
35 | Correct | 124 ms | 25244 KB | Output is correct |
36 | Correct | 127 ms | 25124 KB | Output is correct |
37 | Correct | 125 ms | 25340 KB | Output is correct |
38 | Correct | 122 ms | 25208 KB | Output is correct |
39 | Correct | 126 ms | 25336 KB | Output is correct |
40 | Correct | 80 ms | 25208 KB | Output is correct |
41 | Correct | 79 ms | 25336 KB | Output is correct |
42 | Correct | 70 ms | 25336 KB | Output is correct |
43 | Correct | 66 ms | 25208 KB | Output is correct |
44 | Correct | 82 ms | 25336 KB | Output is correct |
45 | Correct | 80 ms | 25216 KB | Output is correct |
46 | Correct | 71 ms | 25216 KB | Output is correct |
47 | Correct | 68 ms | 25208 KB | Output is correct |
48 | Correct | 1582 ms | 39160 KB | Output is correct |
49 | Correct | 1590 ms | 39256 KB | Output is correct |
50 | Correct | 1586 ms | 39320 KB | Output is correct |
51 | Correct | 1317 ms | 38648 KB | Output is correct |
52 | Correct | 1062 ms | 37636 KB | Output is correct |
53 | Correct | 873 ms | 38392 KB | Output is correct |
54 | Correct | 667 ms | 37300 KB | Output is correct |
55 | Correct | 662 ms | 37132 KB | Output is correct |
56 | Correct | 574 ms | 36856 KB | Output is correct |
57 | Execution timed out | 2559 ms | 124408 KB | Time limit exceeded |
58 | Halted | 0 ms | 0 KB | - |