답안 #299462

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
299462 2020-09-15T00:13:28 Z XmtosX Rope (JOI17_rope) C++17
100 / 100
1771 ms 78072 KB
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,m,a[N],cnt[N],ans[N],cnt1[N],here[N],maxx;
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];
        maxx=max(maxx,cnt[a[i]]);
    }
    for (int i=1;i<=m;i++)
        here[cnt[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)
            {
                if (here[cnt1[i]]==1&&cnt1[i]==maxx)
                    maxx--;
                here[cnt1[i]]--;
                cnt1[i]--;
                here[cnt1[i]]++;
                V.push_back(i);
                tot--;
            }
            for (int j=0;j<v[i].size();j++)
            {
                int idx= v[i][j];
                V.push_back(a[idx]);
                if (here[cnt1[a[idx]]]==1&&cnt1[a[idx]]==maxx)
                    maxx--;
                here[cnt1[a[idx]]]--;
                cnt1[a[idx]]--;
                here[cnt1[a[idx]]]++;
                tot-=(a[idx]==i);
                idx++;
                V.push_back(a[idx]);
                if (here[cnt1[a[idx]]]==1&&cnt1[a[idx]]==maxx)
                    maxx--;
                here[cnt1[a[idx]]]--;
                cnt1[a[idx]]--;
                here[cnt1[a[idx]]]++;
                tot-=(a[idx]==i);
            }
            if (yes&&a[n-1]==i)
            {
                if (here[cnt1[i]]==1&&cnt1[i]==maxx)
                    maxx--;
                here[cnt1[i]]--;
                cnt1[i]--;
                here[cnt1[i]]++;
                V.push_back(i);
                tot--;
            }
            ans[i]=min(ans[i],tot-maxx);
            for (int j=0;j<V.size();j++)
            {
                here[cnt1[V[j]]]--;
                here[cnt[V[j]]]++;
                cnt1[V[j]]=cnt[V[j]];
                maxx=max(maxx,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:49:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |             for (int j=0;j<v[i].size();j++)
      |                          ~^~~~~~~~~~~~
rope.cpp:79:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             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 17 ms 23808 KB Output is correct
7 Correct 17 ms 24064 KB Output is correct
8 Correct 16 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 24024 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 23808 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 16 ms 23808 KB Output is correct
18 Correct 18 ms 23808 KB Output is correct
19 Correct 18 ms 23840 KB Output is correct
20 Correct 17 ms 23808 KB Output is correct
21 Correct 16 ms 23808 KB Output is correct
22 Correct 17 ms 23808 KB Output is correct
23 Correct 17 ms 23808 KB Output is correct
24 Correct 16 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 17 ms 23808 KB Output is correct
7 Correct 17 ms 24064 KB Output is correct
8 Correct 16 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 24024 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 23808 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 16 ms 23808 KB Output is correct
18 Correct 18 ms 23808 KB Output is correct
19 Correct 18 ms 23840 KB Output is correct
20 Correct 17 ms 23808 KB Output is correct
21 Correct 16 ms 23808 KB Output is correct
22 Correct 17 ms 23808 KB Output is correct
23 Correct 17 ms 23808 KB Output is correct
24 Correct 16 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 40 ms 25088 KB Output is correct
28 Correct 39 ms 25080 KB Output is correct
29 Correct 39 ms 24960 KB Output is correct
30 Correct 39 ms 25208 KB Output is correct
31 Correct 39 ms 24952 KB Output is correct
32 Correct 38 ms 25088 KB Output is correct
33 Correct 40 ms 25152 KB Output is correct
34 Correct 34 ms 25024 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 17 ms 23808 KB Output is correct
7 Correct 17 ms 24064 KB Output is correct
8 Correct 16 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 24024 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 23808 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 16 ms 23808 KB Output is correct
18 Correct 18 ms 23808 KB Output is correct
19 Correct 18 ms 23840 KB Output is correct
20 Correct 17 ms 23808 KB Output is correct
21 Correct 16 ms 23808 KB Output is correct
22 Correct 17 ms 23808 KB Output is correct
23 Correct 17 ms 23808 KB Output is correct
24 Correct 16 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 40 ms 25088 KB Output is correct
28 Correct 39 ms 25080 KB Output is correct
29 Correct 39 ms 24960 KB Output is correct
30 Correct 39 ms 25208 KB Output is correct
31 Correct 39 ms 24952 KB Output is correct
32 Correct 38 ms 25088 KB Output is correct
33 Correct 40 ms 25152 KB Output is correct
34 Correct 34 ms 25024 KB Output is correct
35 Correct 44 ms 24832 KB Output is correct
36 Correct 44 ms 24832 KB Output is correct
37 Correct 44 ms 24824 KB Output is correct
38 Correct 44 ms 24832 KB Output is correct
39 Correct 39 ms 24832 KB Output is correct
40 Correct 42 ms 24832 KB Output is correct
41 Correct 42 ms 24824 KB Output is correct
42 Correct 41 ms 24832 KB Output is correct
43 Correct 42 ms 24952 KB Output is correct
44 Correct 44 ms 24952 KB Output is correct
45 Correct 45 ms 24952 KB Output is correct
46 Correct 37 ms 24832 KB Output is correct
47 Correct 43 ms 24832 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 17 ms 23808 KB Output is correct
7 Correct 17 ms 24064 KB Output is correct
8 Correct 16 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 24024 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 23808 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 16 ms 23808 KB Output is correct
18 Correct 18 ms 23808 KB Output is correct
19 Correct 18 ms 23840 KB Output is correct
20 Correct 17 ms 23808 KB Output is correct
21 Correct 16 ms 23808 KB Output is correct
22 Correct 17 ms 23808 KB Output is correct
23 Correct 17 ms 23808 KB Output is correct
24 Correct 16 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 40 ms 25088 KB Output is correct
28 Correct 39 ms 25080 KB Output is correct
29 Correct 39 ms 24960 KB Output is correct
30 Correct 39 ms 25208 KB Output is correct
31 Correct 39 ms 24952 KB Output is correct
32 Correct 38 ms 25088 KB Output is correct
33 Correct 40 ms 25152 KB Output is correct
34 Correct 34 ms 25024 KB Output is correct
35 Correct 44 ms 24832 KB Output is correct
36 Correct 44 ms 24832 KB Output is correct
37 Correct 44 ms 24824 KB Output is correct
38 Correct 44 ms 24832 KB Output is correct
39 Correct 39 ms 24832 KB Output is correct
40 Correct 42 ms 24832 KB Output is correct
41 Correct 42 ms 24824 KB Output is correct
42 Correct 41 ms 24832 KB Output is correct
43 Correct 42 ms 24952 KB Output is correct
44 Correct 44 ms 24952 KB Output is correct
45 Correct 45 ms 24952 KB Output is correct
46 Correct 37 ms 24832 KB Output is correct
47 Correct 43 ms 24832 KB Output is correct
48 Correct 376 ms 34424 KB Output is correct
49 Correct 372 ms 34440 KB Output is correct
50 Correct 381 ms 34424 KB Output is correct
51 Correct 354 ms 34424 KB Output is correct
52 Correct 344 ms 33532 KB Output is correct
53 Correct 309 ms 33804 KB Output is correct
54 Correct 304 ms 32760 KB Output is correct
55 Correct 291 ms 32504 KB Output is correct
56 Correct 286 ms 32120 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 17 ms 23808 KB Output is correct
7 Correct 17 ms 24064 KB Output is correct
8 Correct 16 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 24024 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 23808 KB Output is correct
16 Correct 17 ms 23808 KB Output is correct
17 Correct 16 ms 23808 KB Output is correct
18 Correct 18 ms 23808 KB Output is correct
19 Correct 18 ms 23840 KB Output is correct
20 Correct 17 ms 23808 KB Output is correct
21 Correct 16 ms 23808 KB Output is correct
22 Correct 17 ms 23808 KB Output is correct
23 Correct 17 ms 23808 KB Output is correct
24 Correct 16 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 40 ms 25088 KB Output is correct
28 Correct 39 ms 25080 KB Output is correct
29 Correct 39 ms 24960 KB Output is correct
30 Correct 39 ms 25208 KB Output is correct
31 Correct 39 ms 24952 KB Output is correct
32 Correct 38 ms 25088 KB Output is correct
33 Correct 40 ms 25152 KB Output is correct
34 Correct 34 ms 25024 KB Output is correct
35 Correct 44 ms 24832 KB Output is correct
36 Correct 44 ms 24832 KB Output is correct
37 Correct 44 ms 24824 KB Output is correct
38 Correct 44 ms 24832 KB Output is correct
39 Correct 39 ms 24832 KB Output is correct
40 Correct 42 ms 24832 KB Output is correct
41 Correct 42 ms 24824 KB Output is correct
42 Correct 41 ms 24832 KB Output is correct
43 Correct 42 ms 24952 KB Output is correct
44 Correct 44 ms 24952 KB Output is correct
45 Correct 45 ms 24952 KB Output is correct
46 Correct 37 ms 24832 KB Output is correct
47 Correct 43 ms 24832 KB Output is correct
48 Correct 376 ms 34424 KB Output is correct
49 Correct 372 ms 34440 KB Output is correct
50 Correct 381 ms 34424 KB Output is correct
51 Correct 354 ms 34424 KB Output is correct
52 Correct 344 ms 33532 KB Output is correct
53 Correct 309 ms 33804 KB Output is correct
54 Correct 304 ms 32760 KB Output is correct
55 Correct 291 ms 32504 KB Output is correct
56 Correct 286 ms 32120 KB Output is correct
57 Correct 1771 ms 78072 KB Output is correct
58 Correct 1548 ms 64632 KB Output is correct
59 Correct 1509 ms 64632 KB Output is correct
60 Correct 1648 ms 69520 KB Output is correct
61 Correct 1597 ms 69596 KB Output is correct
62 Correct 723 ms 52344 KB Output is correct
63 Correct 1030 ms 58104 KB Output is correct
64 Correct 892 ms 54700 KB Output is correct
65 Correct 481 ms 45432 KB Output is correct