답안 #20910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
20910 2017-03-19T15:19:19 Z model_code Rope (JOI17_rope) C++14
100 / 100
843 ms 23508 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> pi;

const int INF=5e8;
const int MAX_N=1000005;
int app[MAX_N];

int d[MAX_N],ans[MAX_N];
int N,C;

pi ps[500005];
int pscnt[500005];
void chmin(int& a,int b){
  a=min(a,b);
}

void solve(int n,int* ar,int L,int R){
  if(n&1) return;
  if(n==0){
    for(int i=0;i<C;++i) ans[i]=0;
    return;
  }

  int m=0;
  for(int i=0;i<n;i+=2){
    int a=ar[i],b=ar[i+1];
    if(a>b) swap(a,b);
    ps[m++]={a,b};
  }
  sort(ps,ps+m);
  m=unique(ps,ps+m)-ps;
  memset(pscnt,0,sizeof(pscnt));
  for(int i=0;i<n;i+=2){
    int a=ar[i],b=ar[i+1];
    if(a>b) swap(a,b);
    ++pscnt[lower_bound(ps,ps+m,make_pair(a,b))-ps];
  }
  for(int i=0;i<m;++i) {
    int a=ps[i].first,b=ps[i].second;
    if(a==b) continue;
    int val=N-(app[a]+app[b]-pscnt[i]);
    chmin(ans[a],val);
    chmin(ans[b],val);
  }
  for(int i=0;i<C;++i) d[i]=i;
  sort(d,d+C,[&](int a,int b){
    return app[a]>app[b];
  });
  for(int i=0;i<C;++i) {
    int j;
    for(j=0;(i==j) || (j<C && binary_search(ps,ps+m,make_pair(min(d[i],d[j]),max(d[j],d[i]))));++j);
    if(j<C){
      int val=N-(app[d[i]]+app[d[j]]);
      chmin(ans[d[i]],val);
      chmin(ans[d[j]],val);
    }
  }
}
int n;
int ar[MAX_N];

int main(){
  cin>>n>>C;
  if(C==1){
    puts("0");
    return 0;
  }
  for(int i=0;i<n;++i) scanf("%d",&ar[i]),--ar[i];
  for(int i=0;i<C;++i) ans[i]=INF;

  for(int i=0;i<n;++i) app[ar[i]]++;
  N=n;
  solve(n,ar,-1,-1);
  solve(n-1,ar+1,ar[0],-1);
  solve(n-1,ar,-1,ar[n-1]);
  solve(n-2,ar+1,ar[0],ar[n-1]);
  for(int i=0;i<C;++i) printf("%d\n",ans[i]);
  return 0;
}


Compilation message

rope.cpp: In function 'int main()':
rope.cpp:70:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   for(int i=0;i<n;++i) scanf("%d",&ar[i]),--ar[i];
                                                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 23508 KB Output is correct
2 Correct 0 ms 23508 KB Output is correct
3 Correct 0 ms 23508 KB Output is correct
4 Correct 0 ms 23508 KB Output is correct
5 Correct 0 ms 23508 KB Output is correct
6 Correct 0 ms 23508 KB Output is correct
7 Correct 0 ms 23508 KB Output is correct
8 Correct 0 ms 23508 KB Output is correct
9 Correct 0 ms 23508 KB Output is correct
10 Correct 0 ms 23508 KB Output is correct
11 Correct 0 ms 23508 KB Output is correct
12 Correct 0 ms 23508 KB Output is correct
13 Correct 0 ms 23508 KB Output is correct
14 Correct 0 ms 23508 KB Output is correct
15 Correct 0 ms 23508 KB Output is correct
16 Correct 0 ms 23508 KB Output is correct
17 Correct 0 ms 23508 KB Output is correct
18 Correct 0 ms 23508 KB Output is correct
19 Correct 0 ms 23508 KB Output is correct
20 Correct 0 ms 23508 KB Output is correct
21 Correct 0 ms 23508 KB Output is correct
22 Correct 0 ms 23508 KB Output is correct
23 Correct 0 ms 23508 KB Output is correct
24 Correct 0 ms 23508 KB Output is correct
25 Correct 0 ms 23508 KB Output is correct
26 Correct 0 ms 23508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 23508 KB Output is correct
2 Correct 0 ms 23508 KB Output is correct
3 Correct 0 ms 23508 KB Output is correct
4 Correct 0 ms 23508 KB Output is correct
5 Correct 0 ms 23508 KB Output is correct
6 Correct 0 ms 23508 KB Output is correct
7 Correct 0 ms 23508 KB Output is correct
8 Correct 0 ms 23508 KB Output is correct
9 Correct 0 ms 23508 KB Output is correct
10 Correct 0 ms 23508 KB Output is correct
11 Correct 0 ms 23508 KB Output is correct
12 Correct 0 ms 23508 KB Output is correct
13 Correct 0 ms 23508 KB Output is correct
14 Correct 0 ms 23508 KB Output is correct
15 Correct 0 ms 23508 KB Output is correct
16 Correct 0 ms 23508 KB Output is correct
17 Correct 0 ms 23508 KB Output is correct
18 Correct 0 ms 23508 KB Output is correct
19 Correct 0 ms 23508 KB Output is correct
20 Correct 0 ms 23508 KB Output is correct
21 Correct 0 ms 23508 KB Output is correct
22 Correct 0 ms 23508 KB Output is correct
23 Correct 0 ms 23508 KB Output is correct
24 Correct 0 ms 23508 KB Output is correct
25 Correct 0 ms 23508 KB Output is correct
26 Correct 0 ms 23508 KB Output is correct
27 Correct 16 ms 23508 KB Output is correct
28 Correct 23 ms 23508 KB Output is correct
29 Correct 23 ms 23508 KB Output is correct
30 Correct 16 ms 23508 KB Output is correct
31 Correct 23 ms 23508 KB Output is correct
32 Correct 16 ms 23508 KB Output is correct
33 Correct 16 ms 23508 KB Output is correct
34 Correct 19 ms 23508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 23508 KB Output is correct
2 Correct 0 ms 23508 KB Output is correct
3 Correct 0 ms 23508 KB Output is correct
4 Correct 0 ms 23508 KB Output is correct
5 Correct 0 ms 23508 KB Output is correct
6 Correct 0 ms 23508 KB Output is correct
7 Correct 0 ms 23508 KB Output is correct
8 Correct 0 ms 23508 KB Output is correct
9 Correct 0 ms 23508 KB Output is correct
10 Correct 0 ms 23508 KB Output is correct
11 Correct 0 ms 23508 KB Output is correct
12 Correct 0 ms 23508 KB Output is correct
13 Correct 0 ms 23508 KB Output is correct
14 Correct 0 ms 23508 KB Output is correct
15 Correct 0 ms 23508 KB Output is correct
16 Correct 0 ms 23508 KB Output is correct
17 Correct 0 ms 23508 KB Output is correct
18 Correct 0 ms 23508 KB Output is correct
19 Correct 0 ms 23508 KB Output is correct
20 Correct 0 ms 23508 KB Output is correct
21 Correct 0 ms 23508 KB Output is correct
22 Correct 0 ms 23508 KB Output is correct
23 Correct 0 ms 23508 KB Output is correct
24 Correct 0 ms 23508 KB Output is correct
25 Correct 0 ms 23508 KB Output is correct
26 Correct 0 ms 23508 KB Output is correct
27 Correct 16 ms 23508 KB Output is correct
28 Correct 23 ms 23508 KB Output is correct
29 Correct 23 ms 23508 KB Output is correct
30 Correct 16 ms 23508 KB Output is correct
31 Correct 23 ms 23508 KB Output is correct
32 Correct 16 ms 23508 KB Output is correct
33 Correct 16 ms 23508 KB Output is correct
34 Correct 19 ms 23508 KB Output is correct
35 Correct 39 ms 23508 KB Output is correct
36 Correct 39 ms 23508 KB Output is correct
37 Correct 39 ms 23508 KB Output is correct
38 Correct 39 ms 23508 KB Output is correct
39 Correct 36 ms 23508 KB Output is correct
40 Correct 33 ms 23508 KB Output is correct
41 Correct 33 ms 23508 KB Output is correct
42 Correct 33 ms 23508 KB Output is correct
43 Correct 33 ms 23508 KB Output is correct
44 Correct 36 ms 23508 KB Output is correct
45 Correct 46 ms 23508 KB Output is correct
46 Correct 36 ms 23508 KB Output is correct
47 Correct 46 ms 23508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 23508 KB Output is correct
2 Correct 0 ms 23508 KB Output is correct
3 Correct 0 ms 23508 KB Output is correct
4 Correct 0 ms 23508 KB Output is correct
5 Correct 0 ms 23508 KB Output is correct
6 Correct 0 ms 23508 KB Output is correct
7 Correct 0 ms 23508 KB Output is correct
8 Correct 0 ms 23508 KB Output is correct
9 Correct 0 ms 23508 KB Output is correct
10 Correct 0 ms 23508 KB Output is correct
11 Correct 0 ms 23508 KB Output is correct
12 Correct 0 ms 23508 KB Output is correct
13 Correct 0 ms 23508 KB Output is correct
14 Correct 0 ms 23508 KB Output is correct
15 Correct 0 ms 23508 KB Output is correct
16 Correct 0 ms 23508 KB Output is correct
17 Correct 0 ms 23508 KB Output is correct
18 Correct 0 ms 23508 KB Output is correct
19 Correct 0 ms 23508 KB Output is correct
20 Correct 0 ms 23508 KB Output is correct
21 Correct 0 ms 23508 KB Output is correct
22 Correct 0 ms 23508 KB Output is correct
23 Correct 0 ms 23508 KB Output is correct
24 Correct 0 ms 23508 KB Output is correct
25 Correct 0 ms 23508 KB Output is correct
26 Correct 0 ms 23508 KB Output is correct
27 Correct 16 ms 23508 KB Output is correct
28 Correct 23 ms 23508 KB Output is correct
29 Correct 23 ms 23508 KB Output is correct
30 Correct 16 ms 23508 KB Output is correct
31 Correct 23 ms 23508 KB Output is correct
32 Correct 16 ms 23508 KB Output is correct
33 Correct 16 ms 23508 KB Output is correct
34 Correct 19 ms 23508 KB Output is correct
35 Correct 39 ms 23508 KB Output is correct
36 Correct 39 ms 23508 KB Output is correct
37 Correct 39 ms 23508 KB Output is correct
38 Correct 39 ms 23508 KB Output is correct
39 Correct 36 ms 23508 KB Output is correct
40 Correct 33 ms 23508 KB Output is correct
41 Correct 33 ms 23508 KB Output is correct
42 Correct 33 ms 23508 KB Output is correct
43 Correct 33 ms 23508 KB Output is correct
44 Correct 36 ms 23508 KB Output is correct
45 Correct 46 ms 23508 KB Output is correct
46 Correct 36 ms 23508 KB Output is correct
47 Correct 46 ms 23508 KB Output is correct
48 Correct 526 ms 23508 KB Output is correct
49 Correct 579 ms 23508 KB Output is correct
50 Correct 523 ms 23508 KB Output is correct
51 Correct 506 ms 23508 KB Output is correct
52 Correct 489 ms 23508 KB Output is correct
53 Correct 473 ms 23508 KB Output is correct
54 Correct 453 ms 23508 KB Output is correct
55 Correct 439 ms 23508 KB Output is correct
56 Correct 466 ms 23508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 23508 KB Output is correct
2 Correct 0 ms 23508 KB Output is correct
3 Correct 0 ms 23508 KB Output is correct
4 Correct 0 ms 23508 KB Output is correct
5 Correct 0 ms 23508 KB Output is correct
6 Correct 0 ms 23508 KB Output is correct
7 Correct 0 ms 23508 KB Output is correct
8 Correct 0 ms 23508 KB Output is correct
9 Correct 0 ms 23508 KB Output is correct
10 Correct 0 ms 23508 KB Output is correct
11 Correct 0 ms 23508 KB Output is correct
12 Correct 0 ms 23508 KB Output is correct
13 Correct 0 ms 23508 KB Output is correct
14 Correct 0 ms 23508 KB Output is correct
15 Correct 0 ms 23508 KB Output is correct
16 Correct 0 ms 23508 KB Output is correct
17 Correct 0 ms 23508 KB Output is correct
18 Correct 0 ms 23508 KB Output is correct
19 Correct 0 ms 23508 KB Output is correct
20 Correct 0 ms 23508 KB Output is correct
21 Correct 0 ms 23508 KB Output is correct
22 Correct 0 ms 23508 KB Output is correct
23 Correct 0 ms 23508 KB Output is correct
24 Correct 0 ms 23508 KB Output is correct
25 Correct 0 ms 23508 KB Output is correct
26 Correct 0 ms 23508 KB Output is correct
27 Correct 16 ms 23508 KB Output is correct
28 Correct 23 ms 23508 KB Output is correct
29 Correct 23 ms 23508 KB Output is correct
30 Correct 16 ms 23508 KB Output is correct
31 Correct 23 ms 23508 KB Output is correct
32 Correct 16 ms 23508 KB Output is correct
33 Correct 16 ms 23508 KB Output is correct
34 Correct 19 ms 23508 KB Output is correct
35 Correct 39 ms 23508 KB Output is correct
36 Correct 39 ms 23508 KB Output is correct
37 Correct 39 ms 23508 KB Output is correct
38 Correct 39 ms 23508 KB Output is correct
39 Correct 36 ms 23508 KB Output is correct
40 Correct 33 ms 23508 KB Output is correct
41 Correct 33 ms 23508 KB Output is correct
42 Correct 33 ms 23508 KB Output is correct
43 Correct 33 ms 23508 KB Output is correct
44 Correct 36 ms 23508 KB Output is correct
45 Correct 46 ms 23508 KB Output is correct
46 Correct 36 ms 23508 KB Output is correct
47 Correct 46 ms 23508 KB Output is correct
48 Correct 526 ms 23508 KB Output is correct
49 Correct 579 ms 23508 KB Output is correct
50 Correct 523 ms 23508 KB Output is correct
51 Correct 506 ms 23508 KB Output is correct
52 Correct 489 ms 23508 KB Output is correct
53 Correct 473 ms 23508 KB Output is correct
54 Correct 453 ms 23508 KB Output is correct
55 Correct 439 ms 23508 KB Output is correct
56 Correct 466 ms 23508 KB Output is correct
57 Correct 843 ms 23508 KB Output is correct
58 Correct 756 ms 23508 KB Output is correct
59 Correct 759 ms 23508 KB Output is correct
60 Correct 769 ms 23508 KB Output is correct
61 Correct 773 ms 23508 KB Output is correct
62 Correct 579 ms 23508 KB Output is correct
63 Correct 599 ms 23508 KB Output is correct
64 Correct 609 ms 23508 KB Output is correct
65 Correct 533 ms 23508 KB Output is correct