Submission #169555

# Submission time Handle Problem Language Result Execution time Memory
169555 2019-12-21T02:04:58 Z combi1k1 Rope (JOI17_rope) C++14
100 / 100
944 ms 80724 KB
#include<bits/stdc++.h>

using namespace std;

#define pb      push_back
#define sz(x)   int(x.size())

const int   N   = 1e6 + 5;

int a[N], c[N];

vector<int> pos[N];
vector<int> idx;

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;  cin >> n;
    int m;  cin >> m;   a[n] = m;

    for(int i = 0 ; i < n ; ++i)    {
        int x;  cin >> x;   --x;
        a[i] = x;
        c[x]--;

        pos[x].pb(i);
    }

    idx.resize(m);

    iota(idx.begin(),idx.end(),0);
    sort(idx.begin(),idx.end(),[&](int x,int y) {
        return  c[x] < c[y];
    });

    for(int i = 0 ; i < m ; ++i)    {
        int ans = n - sz(pos[i]);

        for(int p = 0 ; p < 2 ; ++p)    {
            int cnt = 2;
            int add = n;

            for(int x : pos[i]) {
                if (x > 0 && x % 2 != p)    c[a[x - 1]]++,  cnt++;
                if (x < n && x % 2 == p)    c[a[x + 1]]++,  cnt++;
            }
            if (cnt > m)
                cnt = m;

            for(int j = 0 ; j < cnt ; ++j)
                if (add > c[idx[j]] && idx[j] != i)
                    add = c[idx[j]];

            if (ans > n - sz(pos[i]) + add)
                ans = n - sz(pos[i]) + add;

            for(int x : pos[i]) {
                if (x > 0 && x % 2 != p)    c[a[x - 1]]--;
                if (x < n && x % 2 == p)    c[a[x + 1]]--;
            }
        }
        cout << ans << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23804 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 23 ms 23800 KB Output is correct
7 Correct 23 ms 23800 KB Output is correct
8 Correct 27 ms 23800 KB Output is correct
9 Correct 27 ms 23828 KB Output is correct
10 Correct 23 ms 23800 KB Output is correct
11 Correct 22 ms 23800 KB Output is correct
12 Correct 23 ms 23800 KB Output is correct
13 Correct 23 ms 23800 KB Output is correct
14 Correct 23 ms 23800 KB Output is correct
15 Correct 23 ms 23800 KB Output is correct
16 Correct 23 ms 23800 KB Output is correct
17 Correct 23 ms 23800 KB Output is correct
18 Correct 23 ms 23800 KB Output is correct
19 Correct 23 ms 23800 KB Output is correct
20 Correct 23 ms 23800 KB Output is correct
21 Correct 22 ms 23800 KB Output is correct
22 Correct 23 ms 23800 KB Output is correct
23 Correct 23 ms 23804 KB Output is correct
24 Correct 23 ms 23800 KB Output is correct
25 Correct 23 ms 23800 KB Output is correct
26 Correct 23 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23804 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 23 ms 23800 KB Output is correct
7 Correct 23 ms 23800 KB Output is correct
8 Correct 27 ms 23800 KB Output is correct
9 Correct 27 ms 23828 KB Output is correct
10 Correct 23 ms 23800 KB Output is correct
11 Correct 22 ms 23800 KB Output is correct
12 Correct 23 ms 23800 KB Output is correct
13 Correct 23 ms 23800 KB Output is correct
14 Correct 23 ms 23800 KB Output is correct
15 Correct 23 ms 23800 KB Output is correct
16 Correct 23 ms 23800 KB Output is correct
17 Correct 23 ms 23800 KB Output is correct
18 Correct 23 ms 23800 KB Output is correct
19 Correct 23 ms 23800 KB Output is correct
20 Correct 23 ms 23800 KB Output is correct
21 Correct 22 ms 23800 KB Output is correct
22 Correct 23 ms 23800 KB Output is correct
23 Correct 23 ms 23804 KB Output is correct
24 Correct 23 ms 23800 KB Output is correct
25 Correct 23 ms 23800 KB Output is correct
26 Correct 23 ms 23800 KB Output is correct
27 Correct 36 ms 25080 KB Output is correct
28 Correct 36 ms 24952 KB Output is correct
29 Correct 36 ms 24952 KB Output is correct
30 Correct 42 ms 25024 KB Output is correct
31 Correct 36 ms 25084 KB Output is correct
32 Correct 35 ms 25080 KB Output is correct
33 Correct 35 ms 25080 KB Output is correct
34 Correct 35 ms 25080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23804 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 23 ms 23800 KB Output is correct
7 Correct 23 ms 23800 KB Output is correct
8 Correct 27 ms 23800 KB Output is correct
9 Correct 27 ms 23828 KB Output is correct
10 Correct 23 ms 23800 KB Output is correct
11 Correct 22 ms 23800 KB Output is correct
12 Correct 23 ms 23800 KB Output is correct
13 Correct 23 ms 23800 KB Output is correct
14 Correct 23 ms 23800 KB Output is correct
15 Correct 23 ms 23800 KB Output is correct
16 Correct 23 ms 23800 KB Output is correct
17 Correct 23 ms 23800 KB Output is correct
18 Correct 23 ms 23800 KB Output is correct
19 Correct 23 ms 23800 KB Output is correct
20 Correct 23 ms 23800 KB Output is correct
21 Correct 22 ms 23800 KB Output is correct
22 Correct 23 ms 23800 KB Output is correct
23 Correct 23 ms 23804 KB Output is correct
24 Correct 23 ms 23800 KB Output is correct
25 Correct 23 ms 23800 KB Output is correct
26 Correct 23 ms 23800 KB Output is correct
27 Correct 36 ms 25080 KB Output is correct
28 Correct 36 ms 24952 KB Output is correct
29 Correct 36 ms 24952 KB Output is correct
30 Correct 42 ms 25024 KB Output is correct
31 Correct 36 ms 25084 KB Output is correct
32 Correct 35 ms 25080 KB Output is correct
33 Correct 35 ms 25080 KB Output is correct
34 Correct 35 ms 25080 KB Output is correct
35 Correct 41 ms 25176 KB Output is correct
36 Correct 41 ms 25236 KB Output is correct
37 Correct 41 ms 25208 KB Output is correct
38 Correct 41 ms 25208 KB Output is correct
39 Correct 40 ms 25208 KB Output is correct
40 Correct 38 ms 25208 KB Output is correct
41 Correct 38 ms 25336 KB Output is correct
42 Correct 38 ms 25208 KB Output is correct
43 Correct 38 ms 25208 KB Output is correct
44 Correct 38 ms 25208 KB Output is correct
45 Correct 38 ms 25336 KB Output is correct
46 Correct 38 ms 25180 KB Output is correct
47 Correct 38 ms 25208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23804 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 23 ms 23800 KB Output is correct
7 Correct 23 ms 23800 KB Output is correct
8 Correct 27 ms 23800 KB Output is correct
9 Correct 27 ms 23828 KB Output is correct
10 Correct 23 ms 23800 KB Output is correct
11 Correct 22 ms 23800 KB Output is correct
12 Correct 23 ms 23800 KB Output is correct
13 Correct 23 ms 23800 KB Output is correct
14 Correct 23 ms 23800 KB Output is correct
15 Correct 23 ms 23800 KB Output is correct
16 Correct 23 ms 23800 KB Output is correct
17 Correct 23 ms 23800 KB Output is correct
18 Correct 23 ms 23800 KB Output is correct
19 Correct 23 ms 23800 KB Output is correct
20 Correct 23 ms 23800 KB Output is correct
21 Correct 22 ms 23800 KB Output is correct
22 Correct 23 ms 23800 KB Output is correct
23 Correct 23 ms 23804 KB Output is correct
24 Correct 23 ms 23800 KB Output is correct
25 Correct 23 ms 23800 KB Output is correct
26 Correct 23 ms 23800 KB Output is correct
27 Correct 36 ms 25080 KB Output is correct
28 Correct 36 ms 24952 KB Output is correct
29 Correct 36 ms 24952 KB Output is correct
30 Correct 42 ms 25024 KB Output is correct
31 Correct 36 ms 25084 KB Output is correct
32 Correct 35 ms 25080 KB Output is correct
33 Correct 35 ms 25080 KB Output is correct
34 Correct 35 ms 25080 KB Output is correct
35 Correct 41 ms 25176 KB Output is correct
36 Correct 41 ms 25236 KB Output is correct
37 Correct 41 ms 25208 KB Output is correct
38 Correct 41 ms 25208 KB Output is correct
39 Correct 40 ms 25208 KB Output is correct
40 Correct 38 ms 25208 KB Output is correct
41 Correct 38 ms 25336 KB Output is correct
42 Correct 38 ms 25208 KB Output is correct
43 Correct 38 ms 25208 KB Output is correct
44 Correct 38 ms 25208 KB Output is correct
45 Correct 38 ms 25336 KB Output is correct
46 Correct 38 ms 25180 KB Output is correct
47 Correct 38 ms 25208 KB Output is correct
48 Correct 256 ms 38948 KB Output is correct
49 Correct 272 ms 39076 KB Output is correct
50 Correct 270 ms 38904 KB Output is correct
51 Correct 267 ms 38536 KB Output is correct
52 Correct 281 ms 37288 KB Output is correct
53 Correct 228 ms 38136 KB Output is correct
54 Correct 218 ms 37148 KB Output is correct
55 Correct 218 ms 37000 KB Output is correct
56 Correct 215 ms 36728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23804 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 23 ms 23800 KB Output is correct
7 Correct 23 ms 23800 KB Output is correct
8 Correct 27 ms 23800 KB Output is correct
9 Correct 27 ms 23828 KB Output is correct
10 Correct 23 ms 23800 KB Output is correct
11 Correct 22 ms 23800 KB Output is correct
12 Correct 23 ms 23800 KB Output is correct
13 Correct 23 ms 23800 KB Output is correct
14 Correct 23 ms 23800 KB Output is correct
15 Correct 23 ms 23800 KB Output is correct
16 Correct 23 ms 23800 KB Output is correct
17 Correct 23 ms 23800 KB Output is correct
18 Correct 23 ms 23800 KB Output is correct
19 Correct 23 ms 23800 KB Output is correct
20 Correct 23 ms 23800 KB Output is correct
21 Correct 22 ms 23800 KB Output is correct
22 Correct 23 ms 23800 KB Output is correct
23 Correct 23 ms 23804 KB Output is correct
24 Correct 23 ms 23800 KB Output is correct
25 Correct 23 ms 23800 KB Output is correct
26 Correct 23 ms 23800 KB Output is correct
27 Correct 36 ms 25080 KB Output is correct
28 Correct 36 ms 24952 KB Output is correct
29 Correct 36 ms 24952 KB Output is correct
30 Correct 42 ms 25024 KB Output is correct
31 Correct 36 ms 25084 KB Output is correct
32 Correct 35 ms 25080 KB Output is correct
33 Correct 35 ms 25080 KB Output is correct
34 Correct 35 ms 25080 KB Output is correct
35 Correct 41 ms 25176 KB Output is correct
36 Correct 41 ms 25236 KB Output is correct
37 Correct 41 ms 25208 KB Output is correct
38 Correct 41 ms 25208 KB Output is correct
39 Correct 40 ms 25208 KB Output is correct
40 Correct 38 ms 25208 KB Output is correct
41 Correct 38 ms 25336 KB Output is correct
42 Correct 38 ms 25208 KB Output is correct
43 Correct 38 ms 25208 KB Output is correct
44 Correct 38 ms 25208 KB Output is correct
45 Correct 38 ms 25336 KB Output is correct
46 Correct 38 ms 25180 KB Output is correct
47 Correct 38 ms 25208 KB Output is correct
48 Correct 256 ms 38948 KB Output is correct
49 Correct 272 ms 39076 KB Output is correct
50 Correct 270 ms 38904 KB Output is correct
51 Correct 267 ms 38536 KB Output is correct
52 Correct 281 ms 37288 KB Output is correct
53 Correct 228 ms 38136 KB Output is correct
54 Correct 218 ms 37148 KB Output is correct
55 Correct 218 ms 37000 KB Output is correct
56 Correct 215 ms 36728 KB Output is correct
57 Correct 944 ms 80724 KB Output is correct
58 Correct 779 ms 62328 KB Output is correct
59 Correct 805 ms 62116 KB Output is correct
60 Correct 817 ms 66832 KB Output is correct
61 Correct 830 ms 67012 KB Output is correct
62 Correct 448 ms 51264 KB Output is correct
63 Correct 584 ms 56440 KB Output is correct
64 Correct 509 ms 53284 KB Output is correct
65 Correct 323 ms 44732 KB Output is correct