Submission #949559

# Submission time Handle Problem Language Result Execution time Memory
949559 2024-03-19T10:56:54 Z ace5 Rope (JOI17_rope) C++17
80 / 100
2500 ms 114960 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1000001;

vector<int> cc[maxn];
set<pair<int,int>> ck;
int a[maxn];
int u[maxn];
int ans[maxn];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    for(int j = 0;j < n;++j)
    {
        cin >> a[j];
        a[j]--;
        cc[a[j]].push_back(j);
    }
    for(int j = 0;j < m;++j)
    {
        u[j] = cc[j].size();
        ck.insert({-u[j],j});
        ans[j] = n+1;
    }
    for(int j = 0;j < m;++j)
    {
        int op = u[j];
        for(int k = 0;k < cc[j].size();++k)
        {
            if(cc[j][k] == n-1 && n%2 == 1)
                break;
            int pr = a[cc[j][k]^1];
            ck.erase({-u[pr],pr});
            u[pr]--;
            ck.insert({-u[pr],pr});
        }
        ck.erase({-u[j],j});
        ans[j] = min(ans[j],(ck.size() == 0 ? 0 : n-op+(*ck.begin()).first));
        ck.insert({-u[j],j});
        for(int k = 0;k < cc[j].size();++k)
        {
            if(cc[j][k] == n-1 && n%2 == 1)
                break;
            int pr = a[cc[j][k]^1];
            ck.erase({-u[pr],pr});
            u[pr]++;
            ck.insert({-u[pr],pr});
        }
    }
    for(int j = 0;j < m;++j)
    {
        int op = u[j];
        for(int k = 0;k < cc[j].size();++k)
        {
            if(cc[j][k] == n-1 && n%2 == 0)
                break;
            if(cc[j][k] == 0)
                continue;
            int pr = a[((cc[j][k]-1)^1)+1];
            ck.erase({-u[pr],pr});
            u[pr]--;
            ck.insert({-u[pr],pr});
        }
        ck.erase({-u[j],j});
        ans[j] = min(ans[j],(ck.size() == 0 ? 0 : n-op+(*ck.begin()).first));
        ck.insert({-u[j],j});
        for(int k = 0;k < cc[j].size();++k)
        {
            if(cc[j][k] == n-1 && n%2 == 0)
                break;
            if(cc[j][k] == 0)
                continue;
            int pr = a[((cc[j][k]-1)^1)+1];
            ck.erase({-u[pr],pr});
            u[pr]++;
            ck.insert({-u[pr],pr});
        }
        cout << ans[j] << "\n";
    }
}

Compilation message

rope.cpp: In function 'int main()':
rope.cpp:34:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for(int k = 0;k < cc[j].size();++k)
      |                       ~~^~~~~~~~~~~~~~
rope.cpp:46:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for(int k = 0;k < cc[j].size();++k)
      |                       ~~^~~~~~~~~~~~~~
rope.cpp:59:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for(int k = 0;k < cc[j].size();++k)
      |                       ~~^~~~~~~~~~~~~~
rope.cpp:73:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for(int k = 0;k < cc[j].size();++k)
      |                       ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 29276 KB Output is correct
2 Correct 7 ms 29272 KB Output is correct
3 Correct 6 ms 29352 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 6 ms 29276 KB Output is correct
7 Correct 7 ms 29276 KB Output is correct
8 Correct 6 ms 29276 KB Output is correct
9 Correct 7 ms 29276 KB Output is correct
10 Correct 6 ms 29276 KB Output is correct
11 Correct 6 ms 29276 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 6 ms 29276 KB Output is correct
15 Correct 6 ms 29276 KB Output is correct
16 Correct 6 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
19 Correct 6 ms 29528 KB Output is correct
20 Correct 6 ms 29276 KB Output is correct
21 Correct 6 ms 29336 KB Output is correct
22 Correct 6 ms 29276 KB Output is correct
23 Correct 8 ms 29276 KB Output is correct
24 Correct 6 ms 29276 KB Output is correct
25 Correct 6 ms 29352 KB Output is correct
26 Correct 7 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 29276 KB Output is correct
2 Correct 7 ms 29272 KB Output is correct
3 Correct 6 ms 29352 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 6 ms 29276 KB Output is correct
7 Correct 7 ms 29276 KB Output is correct
8 Correct 6 ms 29276 KB Output is correct
9 Correct 7 ms 29276 KB Output is correct
10 Correct 6 ms 29276 KB Output is correct
11 Correct 6 ms 29276 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 6 ms 29276 KB Output is correct
15 Correct 6 ms 29276 KB Output is correct
16 Correct 6 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
19 Correct 6 ms 29528 KB Output is correct
20 Correct 6 ms 29276 KB Output is correct
21 Correct 6 ms 29336 KB Output is correct
22 Correct 6 ms 29276 KB Output is correct
23 Correct 8 ms 29276 KB Output is correct
24 Correct 6 ms 29276 KB Output is correct
25 Correct 6 ms 29352 KB Output is correct
26 Correct 7 ms 29276 KB Output is correct
27 Correct 46 ms 29980 KB Output is correct
28 Correct 34 ms 29788 KB Output is correct
29 Correct 40 ms 29784 KB Output is correct
30 Correct 35 ms 29788 KB Output is correct
31 Correct 42 ms 29788 KB Output is correct
32 Correct 34 ms 29788 KB Output is correct
33 Correct 41 ms 29788 KB Output is correct
34 Correct 35 ms 30044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 29276 KB Output is correct
2 Correct 7 ms 29272 KB Output is correct
3 Correct 6 ms 29352 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 6 ms 29276 KB Output is correct
7 Correct 7 ms 29276 KB Output is correct
8 Correct 6 ms 29276 KB Output is correct
9 Correct 7 ms 29276 KB Output is correct
10 Correct 6 ms 29276 KB Output is correct
11 Correct 6 ms 29276 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 6 ms 29276 KB Output is correct
15 Correct 6 ms 29276 KB Output is correct
16 Correct 6 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
19 Correct 6 ms 29528 KB Output is correct
20 Correct 6 ms 29276 KB Output is correct
21 Correct 6 ms 29336 KB Output is correct
22 Correct 6 ms 29276 KB Output is correct
23 Correct 8 ms 29276 KB Output is correct
24 Correct 6 ms 29276 KB Output is correct
25 Correct 6 ms 29352 KB Output is correct
26 Correct 7 ms 29276 KB Output is correct
27 Correct 46 ms 29980 KB Output is correct
28 Correct 34 ms 29788 KB Output is correct
29 Correct 40 ms 29784 KB Output is correct
30 Correct 35 ms 29788 KB Output is correct
31 Correct 42 ms 29788 KB Output is correct
32 Correct 34 ms 29788 KB Output is correct
33 Correct 41 ms 29788 KB Output is correct
34 Correct 35 ms 30044 KB Output is correct
35 Correct 99 ms 29944 KB Output is correct
36 Correct 95 ms 29788 KB Output is correct
37 Correct 98 ms 29784 KB Output is correct
38 Correct 95 ms 29788 KB Output is correct
39 Correct 94 ms 29784 KB Output is correct
40 Correct 83 ms 30240 KB Output is correct
41 Correct 84 ms 30032 KB Output is correct
42 Correct 83 ms 29968 KB Output is correct
43 Correct 82 ms 29788 KB Output is correct
44 Correct 89 ms 29988 KB Output is correct
45 Correct 85 ms 29784 KB Output is correct
46 Correct 88 ms 30036 KB Output is correct
47 Correct 86 ms 30008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 29276 KB Output is correct
2 Correct 7 ms 29272 KB Output is correct
3 Correct 6 ms 29352 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 6 ms 29276 KB Output is correct
7 Correct 7 ms 29276 KB Output is correct
8 Correct 6 ms 29276 KB Output is correct
9 Correct 7 ms 29276 KB Output is correct
10 Correct 6 ms 29276 KB Output is correct
11 Correct 6 ms 29276 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 6 ms 29276 KB Output is correct
15 Correct 6 ms 29276 KB Output is correct
16 Correct 6 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
19 Correct 6 ms 29528 KB Output is correct
20 Correct 6 ms 29276 KB Output is correct
21 Correct 6 ms 29336 KB Output is correct
22 Correct 6 ms 29276 KB Output is correct
23 Correct 8 ms 29276 KB Output is correct
24 Correct 6 ms 29276 KB Output is correct
25 Correct 6 ms 29352 KB Output is correct
26 Correct 7 ms 29276 KB Output is correct
27 Correct 46 ms 29980 KB Output is correct
28 Correct 34 ms 29788 KB Output is correct
29 Correct 40 ms 29784 KB Output is correct
30 Correct 35 ms 29788 KB Output is correct
31 Correct 42 ms 29788 KB Output is correct
32 Correct 34 ms 29788 KB Output is correct
33 Correct 41 ms 29788 KB Output is correct
34 Correct 35 ms 30044 KB Output is correct
35 Correct 99 ms 29944 KB Output is correct
36 Correct 95 ms 29788 KB Output is correct
37 Correct 98 ms 29784 KB Output is correct
38 Correct 95 ms 29788 KB Output is correct
39 Correct 94 ms 29784 KB Output is correct
40 Correct 83 ms 30240 KB Output is correct
41 Correct 84 ms 30032 KB Output is correct
42 Correct 83 ms 29968 KB Output is correct
43 Correct 82 ms 29788 KB Output is correct
44 Correct 89 ms 29988 KB Output is correct
45 Correct 85 ms 29784 KB Output is correct
46 Correct 88 ms 30036 KB Output is correct
47 Correct 86 ms 30008 KB Output is correct
48 Correct 1201 ms 38076 KB Output is correct
49 Correct 1180 ms 38108 KB Output is correct
50 Correct 1183 ms 38068 KB Output is correct
51 Correct 1059 ms 38244 KB Output is correct
52 Correct 986 ms 37128 KB Output is correct
53 Correct 993 ms 37292 KB Output is correct
54 Correct 952 ms 36244 KB Output is correct
55 Correct 946 ms 36324 KB Output is correct
56 Correct 920 ms 35668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 29276 KB Output is correct
2 Correct 7 ms 29272 KB Output is correct
3 Correct 6 ms 29352 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 6 ms 29276 KB Output is correct
6 Correct 6 ms 29276 KB Output is correct
7 Correct 7 ms 29276 KB Output is correct
8 Correct 6 ms 29276 KB Output is correct
9 Correct 7 ms 29276 KB Output is correct
10 Correct 6 ms 29276 KB Output is correct
11 Correct 6 ms 29276 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 6 ms 29276 KB Output is correct
15 Correct 6 ms 29276 KB Output is correct
16 Correct 6 ms 29276 KB Output is correct
17 Correct 6 ms 29276 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
19 Correct 6 ms 29528 KB Output is correct
20 Correct 6 ms 29276 KB Output is correct
21 Correct 6 ms 29336 KB Output is correct
22 Correct 6 ms 29276 KB Output is correct
23 Correct 8 ms 29276 KB Output is correct
24 Correct 6 ms 29276 KB Output is correct
25 Correct 6 ms 29352 KB Output is correct
26 Correct 7 ms 29276 KB Output is correct
27 Correct 46 ms 29980 KB Output is correct
28 Correct 34 ms 29788 KB Output is correct
29 Correct 40 ms 29784 KB Output is correct
30 Correct 35 ms 29788 KB Output is correct
31 Correct 42 ms 29788 KB Output is correct
32 Correct 34 ms 29788 KB Output is correct
33 Correct 41 ms 29788 KB Output is correct
34 Correct 35 ms 30044 KB Output is correct
35 Correct 99 ms 29944 KB Output is correct
36 Correct 95 ms 29788 KB Output is correct
37 Correct 98 ms 29784 KB Output is correct
38 Correct 95 ms 29788 KB Output is correct
39 Correct 94 ms 29784 KB Output is correct
40 Correct 83 ms 30240 KB Output is correct
41 Correct 84 ms 30032 KB Output is correct
42 Correct 83 ms 29968 KB Output is correct
43 Correct 82 ms 29788 KB Output is correct
44 Correct 89 ms 29988 KB Output is correct
45 Correct 85 ms 29784 KB Output is correct
46 Correct 88 ms 30036 KB Output is correct
47 Correct 86 ms 30008 KB Output is correct
48 Correct 1201 ms 38076 KB Output is correct
49 Correct 1180 ms 38108 KB Output is correct
50 Correct 1183 ms 38068 KB Output is correct
51 Correct 1059 ms 38244 KB Output is correct
52 Correct 986 ms 37128 KB Output is correct
53 Correct 993 ms 37292 KB Output is correct
54 Correct 952 ms 36244 KB Output is correct
55 Correct 946 ms 36324 KB Output is correct
56 Correct 920 ms 35668 KB Output is correct
57 Execution timed out 2603 ms 114960 KB Time limit exceeded
58 Halted 0 ms 0 KB -