답안 #299458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
299458 2020-09-14T23:48:10 Z XmtosX Rope (JOI17_rope) C++17
80 / 100
2500 ms 117840 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<pair<int,int> > s;
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({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(make_pair(cnt[V[j]],V[j]));
                s.insert(make_pair(cnt1[V[j]],V[j]));
            }
            pair<int,int> p = *s.rbegin();
            ans[i]=min(ans[i],tot-p.first);
            for (int j=0;j<V.size();j++)
            {
                s.erase(make_pair(cnt1[V[j]],V[j]));
                s.insert(make_pair(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

rope.cpp: In function 'int main()':
rope.cpp:44:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |             for (int j=0;j<v[i].size();j++)
      |                          ~^~~~~~~~~~~~
rope.cpp:64:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |             for (int j=0;j<V.size();j++)
      |                          ~^~~~~~~~~
rope.cpp:71:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |             for (int j=0;j<V.size();j++)
      |                          ~^~~~~~~~~
rope.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
rope.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 17 ms 23808 KB Output is correct
6 Correct 20 ms 23808 KB Output is correct
7 Correct 17 ms 23808 KB Output is correct
8 Correct 17 ms 23808 KB Output is correct
9 Correct 17 ms 23808 KB Output is correct
10 Correct 16 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 17 ms 23808 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 17 ms 23808 KB Output is correct
15 Correct 16 ms 23936 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 17 ms 23808 KB Output is correct
18 Correct 17 ms 23808 KB Output is correct
19 Correct 17 ms 23808 KB Output is correct
20 Correct 17 ms 23808 KB Output is correct
21 Correct 17 ms 23808 KB Output is correct
22 Correct 17 ms 23808 KB Output is correct
23 Correct 16 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 16 ms 23808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 17 ms 23808 KB Output is correct
6 Correct 20 ms 23808 KB Output is correct
7 Correct 17 ms 23808 KB Output is correct
8 Correct 17 ms 23808 KB Output is correct
9 Correct 17 ms 23808 KB Output is correct
10 Correct 16 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 17 ms 23808 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 17 ms 23808 KB Output is correct
15 Correct 16 ms 23936 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 17 ms 23808 KB Output is correct
18 Correct 17 ms 23808 KB Output is correct
19 Correct 17 ms 23808 KB Output is correct
20 Correct 17 ms 23808 KB Output is correct
21 Correct 17 ms 23808 KB Output is correct
22 Correct 17 ms 23808 KB Output is correct
23 Correct 16 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 16 ms 23808 KB Output is correct
27 Correct 32 ms 25336 KB Output is correct
28 Correct 31 ms 24960 KB Output is correct
29 Correct 32 ms 24960 KB Output is correct
30 Correct 32 ms 25080 KB Output is correct
31 Correct 32 ms 25080 KB Output is correct
32 Correct 32 ms 24956 KB Output is correct
33 Correct 32 ms 24960 KB Output is correct
34 Correct 31 ms 25088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 17 ms 23808 KB Output is correct
6 Correct 20 ms 23808 KB Output is correct
7 Correct 17 ms 23808 KB Output is correct
8 Correct 17 ms 23808 KB Output is correct
9 Correct 17 ms 23808 KB Output is correct
10 Correct 16 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 17 ms 23808 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 17 ms 23808 KB Output is correct
15 Correct 16 ms 23936 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 17 ms 23808 KB Output is correct
18 Correct 17 ms 23808 KB Output is correct
19 Correct 17 ms 23808 KB Output is correct
20 Correct 17 ms 23808 KB Output is correct
21 Correct 17 ms 23808 KB Output is correct
22 Correct 17 ms 23808 KB Output is correct
23 Correct 16 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 16 ms 23808 KB Output is correct
27 Correct 32 ms 25336 KB Output is correct
28 Correct 31 ms 24960 KB Output is correct
29 Correct 32 ms 24960 KB Output is correct
30 Correct 32 ms 25080 KB Output is correct
31 Correct 32 ms 25080 KB Output is correct
32 Correct 32 ms 24956 KB Output is correct
33 Correct 32 ms 24960 KB Output is correct
34 Correct 31 ms 25088 KB Output is correct
35 Correct 147 ms 25208 KB Output is correct
36 Correct 140 ms 25208 KB Output is correct
37 Correct 138 ms 25084 KB Output is correct
38 Correct 138 ms 25216 KB Output is correct
39 Correct 137 ms 25216 KB Output is correct
40 Correct 85 ms 25208 KB Output is correct
41 Correct 84 ms 25216 KB Output is correct
42 Correct 72 ms 25216 KB Output is correct
43 Correct 72 ms 25208 KB Output is correct
44 Correct 88 ms 25208 KB Output is correct
45 Correct 88 ms 25340 KB Output is correct
46 Correct 74 ms 25216 KB Output is correct
47 Correct 73 ms 25208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 17 ms 23808 KB Output is correct
6 Correct 20 ms 23808 KB Output is correct
7 Correct 17 ms 23808 KB Output is correct
8 Correct 17 ms 23808 KB Output is correct
9 Correct 17 ms 23808 KB Output is correct
10 Correct 16 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 17 ms 23808 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 17 ms 23808 KB Output is correct
15 Correct 16 ms 23936 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 17 ms 23808 KB Output is correct
18 Correct 17 ms 23808 KB Output is correct
19 Correct 17 ms 23808 KB Output is correct
20 Correct 17 ms 23808 KB Output is correct
21 Correct 17 ms 23808 KB Output is correct
22 Correct 17 ms 23808 KB Output is correct
23 Correct 16 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 16 ms 23808 KB Output is correct
27 Correct 32 ms 25336 KB Output is correct
28 Correct 31 ms 24960 KB Output is correct
29 Correct 32 ms 24960 KB Output is correct
30 Correct 32 ms 25080 KB Output is correct
31 Correct 32 ms 25080 KB Output is correct
32 Correct 32 ms 24956 KB Output is correct
33 Correct 32 ms 24960 KB Output is correct
34 Correct 31 ms 25088 KB Output is correct
35 Correct 147 ms 25208 KB Output is correct
36 Correct 140 ms 25208 KB Output is correct
37 Correct 138 ms 25084 KB Output is correct
38 Correct 138 ms 25216 KB Output is correct
39 Correct 137 ms 25216 KB Output is correct
40 Correct 85 ms 25208 KB Output is correct
41 Correct 84 ms 25216 KB Output is correct
42 Correct 72 ms 25216 KB Output is correct
43 Correct 72 ms 25208 KB Output is correct
44 Correct 88 ms 25208 KB Output is correct
45 Correct 88 ms 25340 KB Output is correct
46 Correct 74 ms 25216 KB Output is correct
47 Correct 73 ms 25208 KB Output is correct
48 Correct 1737 ms 34852 KB Output is correct
49 Correct 1712 ms 35064 KB Output is correct
50 Correct 1710 ms 34936 KB Output is correct
51 Correct 1471 ms 34680 KB Output is correct
52 Correct 1172 ms 33656 KB Output is correct
53 Correct 930 ms 33784 KB Output is correct
54 Correct 703 ms 33016 KB Output is correct
55 Correct 684 ms 32760 KB Output is correct
56 Correct 595 ms 32248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 16 ms 23808 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 17 ms 23808 KB Output is correct
6 Correct 20 ms 23808 KB Output is correct
7 Correct 17 ms 23808 KB Output is correct
8 Correct 17 ms 23808 KB Output is correct
9 Correct 17 ms 23808 KB Output is correct
10 Correct 16 ms 23808 KB Output is correct
11 Correct 17 ms 23808 KB Output is correct
12 Correct 17 ms 23808 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 17 ms 23808 KB Output is correct
15 Correct 16 ms 23936 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 17 ms 23808 KB Output is correct
18 Correct 17 ms 23808 KB Output is correct
19 Correct 17 ms 23808 KB Output is correct
20 Correct 17 ms 23808 KB Output is correct
21 Correct 17 ms 23808 KB Output is correct
22 Correct 17 ms 23808 KB Output is correct
23 Correct 16 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 16 ms 23808 KB Output is correct
27 Correct 32 ms 25336 KB Output is correct
28 Correct 31 ms 24960 KB Output is correct
29 Correct 32 ms 24960 KB Output is correct
30 Correct 32 ms 25080 KB Output is correct
31 Correct 32 ms 25080 KB Output is correct
32 Correct 32 ms 24956 KB Output is correct
33 Correct 32 ms 24960 KB Output is correct
34 Correct 31 ms 25088 KB Output is correct
35 Correct 147 ms 25208 KB Output is correct
36 Correct 140 ms 25208 KB Output is correct
37 Correct 138 ms 25084 KB Output is correct
38 Correct 138 ms 25216 KB Output is correct
39 Correct 137 ms 25216 KB Output is correct
40 Correct 85 ms 25208 KB Output is correct
41 Correct 84 ms 25216 KB Output is correct
42 Correct 72 ms 25216 KB Output is correct
43 Correct 72 ms 25208 KB Output is correct
44 Correct 88 ms 25208 KB Output is correct
45 Correct 88 ms 25340 KB Output is correct
46 Correct 74 ms 25216 KB Output is correct
47 Correct 73 ms 25208 KB Output is correct
48 Correct 1737 ms 34852 KB Output is correct
49 Correct 1712 ms 35064 KB Output is correct
50 Correct 1710 ms 34936 KB Output is correct
51 Correct 1471 ms 34680 KB Output is correct
52 Correct 1172 ms 33656 KB Output is correct
53 Correct 930 ms 33784 KB Output is correct
54 Correct 703 ms 33016 KB Output is correct
55 Correct 684 ms 32760 KB Output is correct
56 Correct 595 ms 32248 KB Output is correct
57 Execution timed out 2545 ms 117840 KB Time limit exceeded
58 Halted 0 ms 0 KB -