답안 #362819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362819 2021-02-04T12:51:13 Z denkendoemeer Rope (JOI17_rope) C++14
100 / 100
1112 ms 80592 KB
#include<bits/stdc++.h>
using namespace std;
int v[1000005],cost[1000005],ind[1000005];
vector<int>g[1000005];
int cmp(int a,int b)
{
    return cost[a]<cost[b];
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    int n,m,i;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++){
        scanf("%d",&v[i]);
        v[i]--;
        g[v[i]].push_back(i);
        cost[v[i]]--;
    }
    for(i=0;i<m;i++)
        ind[i]=i;
    sort(ind,ind+m,cmp);
    int cul;
    for(cul=0;cul<m;cul++){
        int ans=n-(int)g[cul].size();
        for(i=0;i<2;i++){
            int cnt=0;
            for(auto it:g[cul]){
                if (it>0 && it%2!=i){
                    cost[v[it-1]]++;
                    cnt++;
                }
                if (it<n-1 && (it+1)%2!=i){
                    cost[v[it+1]]++;
                    cnt++;
                }
            }
            cnt=min(cnt+2,m);
            int num=n,j;
            for(j=0;j<cnt;j++){
                if (ind[j]==cul)
                    continue;
                num=min(num,cost[ind[j]]);
            }
            ans=min(ans,n-(int)g[cul].size()+num);
            for(auto it:g[cul]){
                if (it>0 && it%2!=i)
                    cost[v[it-1]]--;
                if (it<n-1 && (it+1)%2!=i)
                    cost[v[it+1]]--;
            }
        }
        printf("%d\n",ans);
    }
return 0;
}

Compilation message

rope.cpp: In function 'int main()':
rope.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
rope.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |         scanf("%d",&v[i]);
      |         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 16 ms 23788 KB Output is correct
4 Correct 16 ms 23788 KB Output is correct
5 Correct 17 ms 23788 KB Output is correct
6 Correct 16 ms 23788 KB Output is correct
7 Correct 19 ms 23788 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 16 ms 23788 KB Output is correct
10 Correct 16 ms 23788 KB Output is correct
11 Correct 17 ms 23788 KB Output is correct
12 Correct 17 ms 24044 KB Output is correct
13 Correct 17 ms 23788 KB Output is correct
14 Correct 16 ms 23788 KB Output is correct
15 Correct 18 ms 23788 KB Output is correct
16 Correct 17 ms 23788 KB Output is correct
17 Correct 17 ms 23788 KB Output is correct
18 Correct 17 ms 23788 KB Output is correct
19 Correct 16 ms 23788 KB Output is correct
20 Correct 16 ms 23788 KB Output is correct
21 Correct 17 ms 23788 KB Output is correct
22 Correct 17 ms 23936 KB Output is correct
23 Correct 17 ms 23788 KB Output is correct
24 Correct 16 ms 23788 KB Output is correct
25 Correct 16 ms 23788 KB Output is correct
26 Correct 16 ms 23788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 16 ms 23788 KB Output is correct
4 Correct 16 ms 23788 KB Output is correct
5 Correct 17 ms 23788 KB Output is correct
6 Correct 16 ms 23788 KB Output is correct
7 Correct 19 ms 23788 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 16 ms 23788 KB Output is correct
10 Correct 16 ms 23788 KB Output is correct
11 Correct 17 ms 23788 KB Output is correct
12 Correct 17 ms 24044 KB Output is correct
13 Correct 17 ms 23788 KB Output is correct
14 Correct 16 ms 23788 KB Output is correct
15 Correct 18 ms 23788 KB Output is correct
16 Correct 17 ms 23788 KB Output is correct
17 Correct 17 ms 23788 KB Output is correct
18 Correct 17 ms 23788 KB Output is correct
19 Correct 16 ms 23788 KB Output is correct
20 Correct 16 ms 23788 KB Output is correct
21 Correct 17 ms 23788 KB Output is correct
22 Correct 17 ms 23936 KB Output is correct
23 Correct 17 ms 23788 KB Output is correct
24 Correct 16 ms 23788 KB Output is correct
25 Correct 16 ms 23788 KB Output is correct
26 Correct 16 ms 23788 KB Output is correct
27 Correct 32 ms 25196 KB Output is correct
28 Correct 31 ms 24940 KB Output is correct
29 Correct 32 ms 25088 KB Output is correct
30 Correct 32 ms 25068 KB Output is correct
31 Correct 32 ms 25068 KB Output is correct
32 Correct 31 ms 25068 KB Output is correct
33 Correct 31 ms 24940 KB Output is correct
34 Correct 32 ms 25000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 16 ms 23788 KB Output is correct
4 Correct 16 ms 23788 KB Output is correct
5 Correct 17 ms 23788 KB Output is correct
6 Correct 16 ms 23788 KB Output is correct
7 Correct 19 ms 23788 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 16 ms 23788 KB Output is correct
10 Correct 16 ms 23788 KB Output is correct
11 Correct 17 ms 23788 KB Output is correct
12 Correct 17 ms 24044 KB Output is correct
13 Correct 17 ms 23788 KB Output is correct
14 Correct 16 ms 23788 KB Output is correct
15 Correct 18 ms 23788 KB Output is correct
16 Correct 17 ms 23788 KB Output is correct
17 Correct 17 ms 23788 KB Output is correct
18 Correct 17 ms 23788 KB Output is correct
19 Correct 16 ms 23788 KB Output is correct
20 Correct 16 ms 23788 KB Output is correct
21 Correct 17 ms 23788 KB Output is correct
22 Correct 17 ms 23936 KB Output is correct
23 Correct 17 ms 23788 KB Output is correct
24 Correct 16 ms 23788 KB Output is correct
25 Correct 16 ms 23788 KB Output is correct
26 Correct 16 ms 23788 KB Output is correct
27 Correct 32 ms 25196 KB Output is correct
28 Correct 31 ms 24940 KB Output is correct
29 Correct 32 ms 25088 KB Output is correct
30 Correct 32 ms 25068 KB Output is correct
31 Correct 32 ms 25068 KB Output is correct
32 Correct 31 ms 25068 KB Output is correct
33 Correct 31 ms 24940 KB Output is correct
34 Correct 32 ms 25000 KB Output is correct
35 Correct 36 ms 25196 KB Output is correct
36 Correct 36 ms 25196 KB Output is correct
37 Correct 36 ms 25196 KB Output is correct
38 Correct 36 ms 25196 KB Output is correct
39 Correct 36 ms 25324 KB Output is correct
40 Correct 34 ms 25324 KB Output is correct
41 Correct 34 ms 25324 KB Output is correct
42 Correct 33 ms 25196 KB Output is correct
43 Correct 37 ms 25344 KB Output is correct
44 Correct 36 ms 25196 KB Output is correct
45 Correct 33 ms 25324 KB Output is correct
46 Correct 34 ms 25196 KB Output is correct
47 Correct 33 ms 25196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 16 ms 23788 KB Output is correct
4 Correct 16 ms 23788 KB Output is correct
5 Correct 17 ms 23788 KB Output is correct
6 Correct 16 ms 23788 KB Output is correct
7 Correct 19 ms 23788 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 16 ms 23788 KB Output is correct
10 Correct 16 ms 23788 KB Output is correct
11 Correct 17 ms 23788 KB Output is correct
12 Correct 17 ms 24044 KB Output is correct
13 Correct 17 ms 23788 KB Output is correct
14 Correct 16 ms 23788 KB Output is correct
15 Correct 18 ms 23788 KB Output is correct
16 Correct 17 ms 23788 KB Output is correct
17 Correct 17 ms 23788 KB Output is correct
18 Correct 17 ms 23788 KB Output is correct
19 Correct 16 ms 23788 KB Output is correct
20 Correct 16 ms 23788 KB Output is correct
21 Correct 17 ms 23788 KB Output is correct
22 Correct 17 ms 23936 KB Output is correct
23 Correct 17 ms 23788 KB Output is correct
24 Correct 16 ms 23788 KB Output is correct
25 Correct 16 ms 23788 KB Output is correct
26 Correct 16 ms 23788 KB Output is correct
27 Correct 32 ms 25196 KB Output is correct
28 Correct 31 ms 24940 KB Output is correct
29 Correct 32 ms 25088 KB Output is correct
30 Correct 32 ms 25068 KB Output is correct
31 Correct 32 ms 25068 KB Output is correct
32 Correct 31 ms 25068 KB Output is correct
33 Correct 31 ms 24940 KB Output is correct
34 Correct 32 ms 25000 KB Output is correct
35 Correct 36 ms 25196 KB Output is correct
36 Correct 36 ms 25196 KB Output is correct
37 Correct 36 ms 25196 KB Output is correct
38 Correct 36 ms 25196 KB Output is correct
39 Correct 36 ms 25324 KB Output is correct
40 Correct 34 ms 25324 KB Output is correct
41 Correct 34 ms 25324 KB Output is correct
42 Correct 33 ms 25196 KB Output is correct
43 Correct 37 ms 25344 KB Output is correct
44 Correct 36 ms 25196 KB Output is correct
45 Correct 33 ms 25324 KB Output is correct
46 Correct 34 ms 25196 KB Output is correct
47 Correct 33 ms 25196 KB Output is correct
48 Correct 284 ms 39068 KB Output is correct
49 Correct 265 ms 39020 KB Output is correct
50 Correct 276 ms 39004 KB Output is correct
51 Correct 254 ms 38636 KB Output is correct
52 Correct 240 ms 37228 KB Output is correct
53 Correct 215 ms 38172 KB Output is correct
54 Correct 201 ms 37100 KB Output is correct
55 Correct 197 ms 36972 KB Output is correct
56 Correct 192 ms 36716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 16 ms 23788 KB Output is correct
3 Correct 16 ms 23788 KB Output is correct
4 Correct 16 ms 23788 KB Output is correct
5 Correct 17 ms 23788 KB Output is correct
6 Correct 16 ms 23788 KB Output is correct
7 Correct 19 ms 23788 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 16 ms 23788 KB Output is correct
10 Correct 16 ms 23788 KB Output is correct
11 Correct 17 ms 23788 KB Output is correct
12 Correct 17 ms 24044 KB Output is correct
13 Correct 17 ms 23788 KB Output is correct
14 Correct 16 ms 23788 KB Output is correct
15 Correct 18 ms 23788 KB Output is correct
16 Correct 17 ms 23788 KB Output is correct
17 Correct 17 ms 23788 KB Output is correct
18 Correct 17 ms 23788 KB Output is correct
19 Correct 16 ms 23788 KB Output is correct
20 Correct 16 ms 23788 KB Output is correct
21 Correct 17 ms 23788 KB Output is correct
22 Correct 17 ms 23936 KB Output is correct
23 Correct 17 ms 23788 KB Output is correct
24 Correct 16 ms 23788 KB Output is correct
25 Correct 16 ms 23788 KB Output is correct
26 Correct 16 ms 23788 KB Output is correct
27 Correct 32 ms 25196 KB Output is correct
28 Correct 31 ms 24940 KB Output is correct
29 Correct 32 ms 25088 KB Output is correct
30 Correct 32 ms 25068 KB Output is correct
31 Correct 32 ms 25068 KB Output is correct
32 Correct 31 ms 25068 KB Output is correct
33 Correct 31 ms 24940 KB Output is correct
34 Correct 32 ms 25000 KB Output is correct
35 Correct 36 ms 25196 KB Output is correct
36 Correct 36 ms 25196 KB Output is correct
37 Correct 36 ms 25196 KB Output is correct
38 Correct 36 ms 25196 KB Output is correct
39 Correct 36 ms 25324 KB Output is correct
40 Correct 34 ms 25324 KB Output is correct
41 Correct 34 ms 25324 KB Output is correct
42 Correct 33 ms 25196 KB Output is correct
43 Correct 37 ms 25344 KB Output is correct
44 Correct 36 ms 25196 KB Output is correct
45 Correct 33 ms 25324 KB Output is correct
46 Correct 34 ms 25196 KB Output is correct
47 Correct 33 ms 25196 KB Output is correct
48 Correct 284 ms 39068 KB Output is correct
49 Correct 265 ms 39020 KB Output is correct
50 Correct 276 ms 39004 KB Output is correct
51 Correct 254 ms 38636 KB Output is correct
52 Correct 240 ms 37228 KB Output is correct
53 Correct 215 ms 38172 KB Output is correct
54 Correct 201 ms 37100 KB Output is correct
55 Correct 197 ms 36972 KB Output is correct
56 Correct 192 ms 36716 KB Output is correct
57 Correct 1112 ms 80592 KB Output is correct
58 Correct 956 ms 62316 KB Output is correct
59 Correct 931 ms 62316 KB Output is correct
60 Correct 1008 ms 66960 KB Output is correct
61 Correct 986 ms 66812 KB Output is correct
62 Correct 461 ms 51244 KB Output is correct
63 Correct 667 ms 56428 KB Output is correct
64 Correct 572 ms 53228 KB Output is correct
65 Correct 319 ms 44780 KB Output is correct