Submission #50287

# Submission time Handle Problem Language Result Execution time Memory
50287 2018-06-09T08:58:55 Z 강태규(#1282, imeimi2000) Rope (JOI17_rope) C++11
100 / 100
1631 ms 153044 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

const int MAXN = 1e6 + 1;
int n, m;
int c[MAXN];
int cnt[MAXN];
int nct[MAXN];
int rev[MAXN];
vector<int> vt[MAXN];
int ans1[MAXN];
int ans2[MAXN];

void solve(int s, int ans[]) {
    for (int i = 1; i <= m; ++i) {
        vt[i].clear();
    }
    for (int i = s; i < n; i += 2) {
        if (c[i] != c[i + 1]) {
            vt[c[i]].push_back(c[i + 1]);
            vt[c[i + 1]].push_back(c[i]);
        }
    }
    for (int i = 1; i <= m; ++i) {
        for (int j : vt[i]) {
            ++nct[j];
        }
        int mx = 0;
        for (int j = m; j; --j) {
            if (rev[j] != i && nct[rev[j]] == 0) {
                mx = max(mx, cnt[rev[j]]);
                break;
            }
        }
        for (int j : vt[i]) {
            mx = max(mx, cnt[j] - nct[j]);
        }
        ans[i] = n - cnt[i] - mx;
        for (int j : vt[i]) {
            nct[j] = 0;
        }
    }
}

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", c + i);
        ++cnt[c[i]];
    }
    
    for (int i = 1; i <= m; ++i) {
        ++nct[cnt[i]];
    }
    
    for (int i = 1; i <= n; ++i) {
        nct[i] += nct[i - 1];
    }
    
    for (int i = 1; i <= m; ++i) {
        rev[nct[cnt[i]]--] = i;
    }
    
    for (int i = 1; i <= n; ++i) {
        nct[i] = 0;
    }
    
    solve(1, ans1);
    solve(2, ans2);
    for (int i = 1; i <= m; ++i) {
        printf("%d\n", min(ans1[i], ans2[i]));
    }
    
    return 0;
}

Compilation message

rope.cpp: In function 'int main()':
rope.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
rope.cpp:65:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", c + i);
         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23800 KB Output is correct
2 Correct 22 ms 23920 KB Output is correct
3 Correct 22 ms 24204 KB Output is correct
4 Correct 22 ms 24204 KB Output is correct
5 Correct 23 ms 24224 KB Output is correct
6 Correct 23 ms 24224 KB Output is correct
7 Correct 24 ms 24224 KB Output is correct
8 Correct 23 ms 24336 KB Output is correct
9 Correct 25 ms 24336 KB Output is correct
10 Correct 24 ms 24336 KB Output is correct
11 Correct 23 ms 24336 KB Output is correct
12 Correct 22 ms 24364 KB Output is correct
13 Correct 22 ms 24364 KB Output is correct
14 Correct 22 ms 24364 KB Output is correct
15 Correct 21 ms 24364 KB Output is correct
16 Correct 22 ms 24364 KB Output is correct
17 Correct 21 ms 24364 KB Output is correct
18 Correct 21 ms 24364 KB Output is correct
19 Correct 21 ms 24364 KB Output is correct
20 Correct 21 ms 24364 KB Output is correct
21 Correct 25 ms 24364 KB Output is correct
22 Correct 23 ms 24364 KB Output is correct
23 Correct 23 ms 24400 KB Output is correct
24 Correct 24 ms 24400 KB Output is correct
25 Correct 22 ms 24400 KB Output is correct
26 Correct 23 ms 24400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23800 KB Output is correct
2 Correct 22 ms 23920 KB Output is correct
3 Correct 22 ms 24204 KB Output is correct
4 Correct 22 ms 24204 KB Output is correct
5 Correct 23 ms 24224 KB Output is correct
6 Correct 23 ms 24224 KB Output is correct
7 Correct 24 ms 24224 KB Output is correct
8 Correct 23 ms 24336 KB Output is correct
9 Correct 25 ms 24336 KB Output is correct
10 Correct 24 ms 24336 KB Output is correct
11 Correct 23 ms 24336 KB Output is correct
12 Correct 22 ms 24364 KB Output is correct
13 Correct 22 ms 24364 KB Output is correct
14 Correct 22 ms 24364 KB Output is correct
15 Correct 21 ms 24364 KB Output is correct
16 Correct 22 ms 24364 KB Output is correct
17 Correct 21 ms 24364 KB Output is correct
18 Correct 21 ms 24364 KB Output is correct
19 Correct 21 ms 24364 KB Output is correct
20 Correct 21 ms 24364 KB Output is correct
21 Correct 25 ms 24364 KB Output is correct
22 Correct 23 ms 24364 KB Output is correct
23 Correct 23 ms 24400 KB Output is correct
24 Correct 24 ms 24400 KB Output is correct
25 Correct 22 ms 24400 KB Output is correct
26 Correct 23 ms 24400 KB Output is correct
27 Correct 35 ms 25928 KB Output is correct
28 Correct 37 ms 26044 KB Output is correct
29 Correct 33 ms 26308 KB Output is correct
30 Correct 32 ms 26308 KB Output is correct
31 Correct 33 ms 26824 KB Output is correct
32 Correct 33 ms 26852 KB Output is correct
33 Correct 35 ms 27080 KB Output is correct
34 Correct 41 ms 27116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23800 KB Output is correct
2 Correct 22 ms 23920 KB Output is correct
3 Correct 22 ms 24204 KB Output is correct
4 Correct 22 ms 24204 KB Output is correct
5 Correct 23 ms 24224 KB Output is correct
6 Correct 23 ms 24224 KB Output is correct
7 Correct 24 ms 24224 KB Output is correct
8 Correct 23 ms 24336 KB Output is correct
9 Correct 25 ms 24336 KB Output is correct
10 Correct 24 ms 24336 KB Output is correct
11 Correct 23 ms 24336 KB Output is correct
12 Correct 22 ms 24364 KB Output is correct
13 Correct 22 ms 24364 KB Output is correct
14 Correct 22 ms 24364 KB Output is correct
15 Correct 21 ms 24364 KB Output is correct
16 Correct 22 ms 24364 KB Output is correct
17 Correct 21 ms 24364 KB Output is correct
18 Correct 21 ms 24364 KB Output is correct
19 Correct 21 ms 24364 KB Output is correct
20 Correct 21 ms 24364 KB Output is correct
21 Correct 25 ms 24364 KB Output is correct
22 Correct 23 ms 24364 KB Output is correct
23 Correct 23 ms 24400 KB Output is correct
24 Correct 24 ms 24400 KB Output is correct
25 Correct 22 ms 24400 KB Output is correct
26 Correct 23 ms 24400 KB Output is correct
27 Correct 35 ms 25928 KB Output is correct
28 Correct 37 ms 26044 KB Output is correct
29 Correct 33 ms 26308 KB Output is correct
30 Correct 32 ms 26308 KB Output is correct
31 Correct 33 ms 26824 KB Output is correct
32 Correct 33 ms 26852 KB Output is correct
33 Correct 35 ms 27080 KB Output is correct
34 Correct 41 ms 27116 KB Output is correct
35 Correct 39 ms 27732 KB Output is correct
36 Correct 42 ms 28084 KB Output is correct
37 Correct 41 ms 28372 KB Output is correct
38 Correct 39 ms 28736 KB Output is correct
39 Correct 38 ms 29200 KB Output is correct
40 Correct 40 ms 29572 KB Output is correct
41 Correct 41 ms 29944 KB Output is correct
42 Correct 34 ms 30316 KB Output is correct
43 Correct 40 ms 30680 KB Output is correct
44 Correct 40 ms 31064 KB Output is correct
45 Correct 35 ms 31404 KB Output is correct
46 Correct 36 ms 31796 KB Output is correct
47 Correct 38 ms 32140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23800 KB Output is correct
2 Correct 22 ms 23920 KB Output is correct
3 Correct 22 ms 24204 KB Output is correct
4 Correct 22 ms 24204 KB Output is correct
5 Correct 23 ms 24224 KB Output is correct
6 Correct 23 ms 24224 KB Output is correct
7 Correct 24 ms 24224 KB Output is correct
8 Correct 23 ms 24336 KB Output is correct
9 Correct 25 ms 24336 KB Output is correct
10 Correct 24 ms 24336 KB Output is correct
11 Correct 23 ms 24336 KB Output is correct
12 Correct 22 ms 24364 KB Output is correct
13 Correct 22 ms 24364 KB Output is correct
14 Correct 22 ms 24364 KB Output is correct
15 Correct 21 ms 24364 KB Output is correct
16 Correct 22 ms 24364 KB Output is correct
17 Correct 21 ms 24364 KB Output is correct
18 Correct 21 ms 24364 KB Output is correct
19 Correct 21 ms 24364 KB Output is correct
20 Correct 21 ms 24364 KB Output is correct
21 Correct 25 ms 24364 KB Output is correct
22 Correct 23 ms 24364 KB Output is correct
23 Correct 23 ms 24400 KB Output is correct
24 Correct 24 ms 24400 KB Output is correct
25 Correct 22 ms 24400 KB Output is correct
26 Correct 23 ms 24400 KB Output is correct
27 Correct 35 ms 25928 KB Output is correct
28 Correct 37 ms 26044 KB Output is correct
29 Correct 33 ms 26308 KB Output is correct
30 Correct 32 ms 26308 KB Output is correct
31 Correct 33 ms 26824 KB Output is correct
32 Correct 33 ms 26852 KB Output is correct
33 Correct 35 ms 27080 KB Output is correct
34 Correct 41 ms 27116 KB Output is correct
35 Correct 39 ms 27732 KB Output is correct
36 Correct 42 ms 28084 KB Output is correct
37 Correct 41 ms 28372 KB Output is correct
38 Correct 39 ms 28736 KB Output is correct
39 Correct 38 ms 29200 KB Output is correct
40 Correct 40 ms 29572 KB Output is correct
41 Correct 41 ms 29944 KB Output is correct
42 Correct 34 ms 30316 KB Output is correct
43 Correct 40 ms 30680 KB Output is correct
44 Correct 40 ms 31064 KB Output is correct
45 Correct 35 ms 31404 KB Output is correct
46 Correct 36 ms 31796 KB Output is correct
47 Correct 38 ms 32140 KB Output is correct
48 Correct 224 ms 49792 KB Output is correct
49 Correct 240 ms 54428 KB Output is correct
50 Correct 227 ms 58840 KB Output is correct
51 Correct 223 ms 63112 KB Output is correct
52 Correct 222 ms 65660 KB Output is correct
53 Correct 204 ms 70724 KB Output is correct
54 Correct 207 ms 74112 KB Output is correct
55 Correct 182 ms 78464 KB Output is correct
56 Correct 178 ms 82616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23800 KB Output is correct
2 Correct 22 ms 23920 KB Output is correct
3 Correct 22 ms 24204 KB Output is correct
4 Correct 22 ms 24204 KB Output is correct
5 Correct 23 ms 24224 KB Output is correct
6 Correct 23 ms 24224 KB Output is correct
7 Correct 24 ms 24224 KB Output is correct
8 Correct 23 ms 24336 KB Output is correct
9 Correct 25 ms 24336 KB Output is correct
10 Correct 24 ms 24336 KB Output is correct
11 Correct 23 ms 24336 KB Output is correct
12 Correct 22 ms 24364 KB Output is correct
13 Correct 22 ms 24364 KB Output is correct
14 Correct 22 ms 24364 KB Output is correct
15 Correct 21 ms 24364 KB Output is correct
16 Correct 22 ms 24364 KB Output is correct
17 Correct 21 ms 24364 KB Output is correct
18 Correct 21 ms 24364 KB Output is correct
19 Correct 21 ms 24364 KB Output is correct
20 Correct 21 ms 24364 KB Output is correct
21 Correct 25 ms 24364 KB Output is correct
22 Correct 23 ms 24364 KB Output is correct
23 Correct 23 ms 24400 KB Output is correct
24 Correct 24 ms 24400 KB Output is correct
25 Correct 22 ms 24400 KB Output is correct
26 Correct 23 ms 24400 KB Output is correct
27 Correct 35 ms 25928 KB Output is correct
28 Correct 37 ms 26044 KB Output is correct
29 Correct 33 ms 26308 KB Output is correct
30 Correct 32 ms 26308 KB Output is correct
31 Correct 33 ms 26824 KB Output is correct
32 Correct 33 ms 26852 KB Output is correct
33 Correct 35 ms 27080 KB Output is correct
34 Correct 41 ms 27116 KB Output is correct
35 Correct 39 ms 27732 KB Output is correct
36 Correct 42 ms 28084 KB Output is correct
37 Correct 41 ms 28372 KB Output is correct
38 Correct 39 ms 28736 KB Output is correct
39 Correct 38 ms 29200 KB Output is correct
40 Correct 40 ms 29572 KB Output is correct
41 Correct 41 ms 29944 KB Output is correct
42 Correct 34 ms 30316 KB Output is correct
43 Correct 40 ms 30680 KB Output is correct
44 Correct 40 ms 31064 KB Output is correct
45 Correct 35 ms 31404 KB Output is correct
46 Correct 36 ms 31796 KB Output is correct
47 Correct 38 ms 32140 KB Output is correct
48 Correct 224 ms 49792 KB Output is correct
49 Correct 240 ms 54428 KB Output is correct
50 Correct 227 ms 58840 KB Output is correct
51 Correct 223 ms 63112 KB Output is correct
52 Correct 222 ms 65660 KB Output is correct
53 Correct 204 ms 70724 KB Output is correct
54 Correct 207 ms 74112 KB Output is correct
55 Correct 182 ms 78464 KB Output is correct
56 Correct 178 ms 82616 KB Output is correct
57 Correct 1631 ms 138984 KB Output is correct
58 Correct 1355 ms 138984 KB Output is correct
59 Correct 1397 ms 138984 KB Output is correct
60 Correct 1428 ms 142688 KB Output is correct
61 Correct 1478 ms 149552 KB Output is correct
62 Correct 578 ms 149552 KB Output is correct
63 Correct 941 ms 150252 KB Output is correct
64 Correct 792 ms 153044 KB Output is correct
65 Correct 332 ms 153044 KB Output is correct