답안 #1029910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1029910 2024-07-21T13:41:22 Z adaawf Council (JOI23_council) C++17
70 / 100
4000 ms 805560 KB
#include <bits/stdc++.h>
using namespace std;
bool a[300005][21];
int c[21], da[21], db[21], z = 0, zz = 0;
int x[300005], y[300005], d[300005];
vector<vector<int>> f, g;
vector<vector<deque<pair<int, int>>>> dd;
priority_queue<pair<long long int, pair<int, int>>> q;
int ch(int x) {
    return __builtin_popcount(x);
}
void trans(int x, int y, int z, int t, int w, int l) {
    int h = dd[z][t].size();
    for (auto w : dd[x][y]) {
        dd[z][t].push_back({w.first - l, w.second});
    }
    sort(dd[z][t].begin(), dd[z][t].end());
    pair<int, int> res = {-1, -1};
    while (dd[z][t].size() >= 2) {
        auto h = dd[z][t].front();
        if (h.second != (dd[z][t].back()).second) res = h;
        dd[z][t].pop_front();
    }
    if (res.first != -1) dd[z][t].push_back(res);
    if (dd[z][t].size() != h) q.push({w, {z, t}});
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m, l = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
            c[j] += a[i][j];
        }
    }
    for (int j = 0; j < m; j++) {
        if (c[j] == n / 2) {
            da[j] = ++z;
        }
        else if (c[j] == (n / 2) + 1) {
            db[j] = ++zz;
        }
        else if (c[j] < n / 2) l++;
    }
    for (int i = 1; i <= n; i++) {
        int h = 0, k = 0;
        for (int j = 0; j < m; j++) {
            if (a[i][j] == 1) {
                if (da[j] != 0) {
                    h += (1 << (da[j] - 1));
                }
                else if (db[j] != 0) {
                    k += (1 << (db[j] - 1));
                }
            }
        }
        x[i] = (1 << z) - h - 1;
        y[i] = (1 << zz) - k - 1;
        d[i] = k;
    }
    g = vector<vector<int>>((1 << z), vector<int>(1 << zz, 0));
    dd = vector<vector<deque<pair<int, int>>>>((1 << z), vector<deque<pair<int, int>>>(1 << zz));
    for (int i = 1; i <= n; i++) {
        dd[x[i]][y[i]].push_back({ch(x[i]) + ch(y[i]), i});
        if (dd[x[i]][y[i]].size() > 2) dd[x[i]][y[i]].pop_back();
        //cout << i << " " << x[i] << " " << y[i] << " " << d[i] << '\n';
        if (dd[x[i]][y[i]].size() == 1) q.push({ch(x[i]) + ch(y[i]), {x[i], y[i]}});
    }
    while (!q.empty()) {
        auto p = q.top();
        q.pop();
        int x = p.first, u = p.second.first, v = p.second.second;
        if (dd[u][v].empty() || g[u][v] == 1) continue;
        g[u][v] = 1;
        for (int i = 0; i < z; i++) {
            if (u & (1 << i)) {
                trans(u, v, u - (1 << i), v, x - 1, 1);
            }
        }
        for (int i = 0; i < zz; i++) {
            if (v & (1 << i)) {
                trans(u, v, u, v - (1 << i), x - 1, 1);
            }
        }
    }
    f = vector<vector<int>>((1 << z), vector<int>(1 << zz, -1e9));
    for (int i = 0; i < (1 << z); i++) {
        for (int j = 0; j < (1 << zz); j++) {
            if (g[i][j] == 1) {
                f[i][j] = ch(i) + ch(j);
                /*for (auto w : dd[i][j]) cout << w.first << "|" << w.second << " ";
                cout << '\n';*/
                q.push({f[i][j], {i, j}});
            }
        }
    }
    while (!q.empty()) {
        auto p = q.top();
        q.pop();
        int x = p.first, u = p.second.first, v = p.second.second;
        /*cout << 12131 << " " << u << " " << v << '\n';
        for (auto w : dd[u][v]) cout << w.first << "|" << w.second << " ";
        cout << '\n';*/
        for (int i = 0; i < z; i++) {
            if (!(u & (1 << i))) {
                trans(u, v, u + (1 << i), v, x, 0);
            }
        }
        for (int i = 0; i < zz; i++) {
            if (!(v & (1 << i))) {
                trans(u, v, u, v + (1 << i), x, 0);
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        int h = 0;
        for (auto w : dd[x[i]][d[i]]) {
            if (w.second != i) {
                h = max(h, w.first);
                //cout << i << " " << x[i] << " " << d[i] << " " << w.first << " " << w.second << '\n';
            }
        }
        h += ch(y[i]);
        cout << m - (z + zz - h) - l << '\n';
    }
}

Compilation message

council.cpp: In function 'void trans(int, int, int, int, int, int)':
council.cpp:25:25: warning: comparison of integer expressions of different signedness: 'std::deque<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |     if (dd[z][t].size() != h) q.push({w, {z, t}});
      |         ~~~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 3 ms 5208 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 3210 ms 805560 KB Output is correct
6 Correct 1 ms 4564 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 3578 ms 729676 KB Output is correct
11 Correct 3502 ms 729568 KB Output is correct
12 Correct 3692 ms 731648 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 3 ms 5212 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4564 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 2 ms 4700 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 3 ms 5212 KB Output is correct
40 Correct 2 ms 5212 KB Output is correct
41 Correct 24 ms 16984 KB Output is correct
42 Correct 1 ms 4856 KB Output is correct
43 Correct 2 ms 4624 KB Output is correct
44 Correct 26 ms 15708 KB Output is correct
45 Correct 29 ms 16220 KB Output is correct
46 Correct 324 ms 104544 KB Output is correct
47 Correct 5 ms 5980 KB Output is correct
48 Correct 1 ms 4564 KB Output is correct
49 Correct 314 ms 93780 KB Output is correct
50 Correct 334 ms 94276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 3 ms 5208 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 3210 ms 805560 KB Output is correct
6 Correct 1 ms 4564 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 3578 ms 729676 KB Output is correct
11 Correct 3502 ms 729568 KB Output is correct
12 Correct 3692 ms 731648 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 3 ms 5212 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4564 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 2 ms 4700 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 3 ms 5212 KB Output is correct
40 Correct 2 ms 5212 KB Output is correct
41 Correct 24 ms 16984 KB Output is correct
42 Correct 1 ms 4856 KB Output is correct
43 Correct 2 ms 4624 KB Output is correct
44 Correct 26 ms 15708 KB Output is correct
45 Correct 29 ms 16220 KB Output is correct
46 Correct 324 ms 104544 KB Output is correct
47 Correct 5 ms 5980 KB Output is correct
48 Correct 1 ms 4564 KB Output is correct
49 Correct 314 ms 93780 KB Output is correct
50 Correct 334 ms 94276 KB Output is correct
51 Correct 3 ms 4700 KB Output is correct
52 Correct 3 ms 4672 KB Output is correct
53 Correct 4 ms 4696 KB Output is correct
54 Execution timed out 4019 ms 740088 KB Time limit exceeded
55 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 55 ms 11836 KB Output is correct
3 Correct 45 ms 11856 KB Output is correct
4 Correct 41 ms 11188 KB Output is correct
5 Correct 45 ms 11856 KB Output is correct
6 Correct 45 ms 11092 KB Output is correct
7 Correct 60 ms 11832 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4524 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 55 ms 11836 KB Output is correct
3 Correct 45 ms 11856 KB Output is correct
4 Correct 41 ms 11188 KB Output is correct
5 Correct 45 ms 11856 KB Output is correct
6 Correct 45 ms 11092 KB Output is correct
7 Correct 60 ms 11832 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4524 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 174 ms 17388 KB Output is correct
21 Correct 185 ms 16208 KB Output is correct
22 Correct 170 ms 16208 KB Output is correct
23 Correct 159 ms 16812 KB Output is correct
24 Correct 160 ms 16468 KB Output is correct
25 Correct 157 ms 16464 KB Output is correct
26 Correct 200 ms 17236 KB Output is correct
27 Correct 3 ms 5328 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4560 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 1 ms 4440 KB Output is correct
40 Correct 1 ms 4440 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4696 KB Output is correct
43 Correct 1 ms 4696 KB Output is correct
44 Correct 2 ms 5072 KB Output is correct
45 Correct 3 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 55 ms 11836 KB Output is correct
3 Correct 45 ms 11856 KB Output is correct
4 Correct 41 ms 11188 KB Output is correct
5 Correct 45 ms 11856 KB Output is correct
6 Correct 45 ms 11092 KB Output is correct
7 Correct 60 ms 11832 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4524 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 174 ms 17388 KB Output is correct
21 Correct 185 ms 16208 KB Output is correct
22 Correct 170 ms 16208 KB Output is correct
23 Correct 159 ms 16812 KB Output is correct
24 Correct 160 ms 16468 KB Output is correct
25 Correct 157 ms 16464 KB Output is correct
26 Correct 200 ms 17236 KB Output is correct
27 Correct 3 ms 5328 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4560 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 1 ms 4440 KB Output is correct
40 Correct 1 ms 4440 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4696 KB Output is correct
43 Correct 1 ms 4696 KB Output is correct
44 Correct 2 ms 5072 KB Output is correct
45 Correct 3 ms 5212 KB Output is correct
46 Correct 2 ms 5212 KB Output is correct
47 Correct 328 ms 32688 KB Output is correct
48 Correct 261 ms 24508 KB Output is correct
49 Correct 252 ms 24404 KB Output is correct
50 Correct 195 ms 19028 KB Output is correct
51 Correct 195 ms 18868 KB Output is correct
52 Correct 223 ms 18768 KB Output is correct
53 Correct 299 ms 30504 KB Output is correct
54 Correct 23 ms 16984 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 23 ms 15828 KB Output is correct
58 Correct 24 ms 16344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 55 ms 11836 KB Output is correct
3 Correct 45 ms 11856 KB Output is correct
4 Correct 41 ms 11188 KB Output is correct
5 Correct 45 ms 11856 KB Output is correct
6 Correct 45 ms 11092 KB Output is correct
7 Correct 60 ms 11832 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4524 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 174 ms 17388 KB Output is correct
21 Correct 185 ms 16208 KB Output is correct
22 Correct 170 ms 16208 KB Output is correct
23 Correct 159 ms 16812 KB Output is correct
24 Correct 160 ms 16468 KB Output is correct
25 Correct 157 ms 16464 KB Output is correct
26 Correct 200 ms 17236 KB Output is correct
27 Correct 3 ms 5328 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4560 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 1 ms 4440 KB Output is correct
39 Correct 1 ms 4440 KB Output is correct
40 Correct 1 ms 4440 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4696 KB Output is correct
43 Correct 1 ms 4696 KB Output is correct
44 Correct 2 ms 5072 KB Output is correct
45 Correct 3 ms 5212 KB Output is correct
46 Correct 2 ms 5212 KB Output is correct
47 Correct 328 ms 32688 KB Output is correct
48 Correct 261 ms 24508 KB Output is correct
49 Correct 252 ms 24404 KB Output is correct
50 Correct 195 ms 19028 KB Output is correct
51 Correct 195 ms 18868 KB Output is correct
52 Correct 223 ms 18768 KB Output is correct
53 Correct 299 ms 30504 KB Output is correct
54 Correct 23 ms 16984 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 23 ms 15828 KB Output is correct
58 Correct 24 ms 16344 KB Output is correct
59 Correct 265 ms 20156 KB Output is correct
60 Correct 545 ms 187564 KB Output is correct
61 Correct 541 ms 187820 KB Output is correct
62 Correct 570 ms 187940 KB Output is correct
63 Correct 487 ms 74928 KB Output is correct
64 Correct 692 ms 120008 KB Output is correct
65 Correct 685 ms 120164 KB Output is correct
66 Correct 245 ms 20820 KB Output is correct
67 Correct 212 ms 20564 KB Output is correct
68 Correct 313 ms 20540 KB Output is correct
69 Correct 717 ms 113152 KB Output is correct
70 Correct 267 ms 104556 KB Output is correct
71 Correct 4 ms 5980 KB Output is correct
72 Correct 2 ms 4700 KB Output is correct
73 Correct 274 ms 94004 KB Output is correct
74 Correct 324 ms 94156 KB Output is correct
75 Correct 346 ms 95952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 3 ms 5208 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 3210 ms 805560 KB Output is correct
6 Correct 1 ms 4564 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 3578 ms 729676 KB Output is correct
11 Correct 3502 ms 729568 KB Output is correct
12 Correct 3692 ms 731648 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 3 ms 5212 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4564 KB Output is correct
32 Correct 2 ms 4444 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 2 ms 4700 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 3 ms 5212 KB Output is correct
40 Correct 2 ms 5212 KB Output is correct
41 Correct 24 ms 16984 KB Output is correct
42 Correct 1 ms 4856 KB Output is correct
43 Correct 2 ms 4624 KB Output is correct
44 Correct 26 ms 15708 KB Output is correct
45 Correct 29 ms 16220 KB Output is correct
46 Correct 324 ms 104544 KB Output is correct
47 Correct 5 ms 5980 KB Output is correct
48 Correct 1 ms 4564 KB Output is correct
49 Correct 314 ms 93780 KB Output is correct
50 Correct 334 ms 94276 KB Output is correct
51 Correct 3 ms 4700 KB Output is correct
52 Correct 3 ms 4672 KB Output is correct
53 Correct 4 ms 4696 KB Output is correct
54 Execution timed out 4019 ms 740088 KB Time limit exceeded
55 Halted 0 ms 0 KB -