답안 #849041

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
849041 2023-09-14T01:57:28 Z hngwlog 철인 이종 경기 (APIO18_duathlon) C++14
15 / 100
29 ms 10836 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define _size(x) (int)x.size()
#define BIT(i, x) ((x >> i) & 1)
#define MASK(n) ((1 << n) - 1)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define FOR(i, a, b) for (int i = a, _b = (b); i <= _b; i++)
#define FORD(i, a, b) for (int i = a, _b = (b); i >= _b; i--)
#define FORB1(i, mask) for (int i = mask; i > 0; i ^= i & - i)
#define FORB0(i, n, mask) for (int i = ((1 << n) - 1) ^ mask; i > 0; i ^= i & - i)
#define FORALL(i, a) for (auto i: a)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);

int n, m;
vector<vector<int>> adj;

namespace subtask1 {

    void main() {

        vector<vector<vector<int>>> f(n + 1, vector<vector<int>>(n + 1, vector<int>(n + 1)));
        FOR(i, 1, n) {
            vector<vector<int>> g((1 << n), vector<int>(n));
            FORALL(j, adj[i]) {
                if (j == i) continue;
                g[(1 << (i - 1)) | (1 << (j - 1))][j - 1] = 1;
            }
            FOR(mask, 0, MASK(n)) {
                FORB1(_mask, mask) {
                    int u = __builtin_ctz(_mask);
                    if (!g[mask][u]) continue;
                    FORB1(__mask, mask) {
                        int v = __builtin_ctz(__mask);
                        if (i == u + 1 || i == v + 1 || u == v) continue;
                        f[i][v + 1][u + 1]++;
                    }
                    FORALL(v, adj[u + 1]) {
                        if (BIT(v - 1, mask)) continue;
                        g[mask | (1 << (v - 1))][v - 1] = 1;
                    }
                }
            }
        }
        int ans = 0;
        FOR(i, 1, n) FOR(j, 1, n) FOR(z, 1, n) {
            if (i == j || i == z || j == z) continue;
            ans += (f[i][j][z] > 0);
        }
        cout << ans << '\n';
    }
}

namespace subtask2 {

    void main() {


    }
}

bool checkSub3() {

    return false;
}


namespace subtask3 {

    void main() {


    }
}

vector<int> vis_check;

int dfs_check(int p, int u) {

    int res = 1;
    vis_check[u]++;
    FORALL(v, adj[u]) {
        if (v == p) continue;
        if (vis_check[v]) return 0;
        res = min(res, dfs_check(u, v));
    }
    return res;
}

bool checkSub45() {

    vis_check.resize(n + 1);
    int res = 1;
    FOR(u, 1, n) if (!vis_check[u]) res = min(res, dfs_check(- 1, u));
    if (res) return true;
    return false;
}

namespace subtask4 {

    vector<int> vis, child;
    vector<vector<int>> a;

    void dfs(int p, int u) {

        a[p][u]++;
        vis[u]++;
        FORALL(v, adj[u]) {
            if (vis[v]) continue;
            dfs(p, v);
            child[u] += child[v];
        }
    }

    void main() {

        a.assign(n + 1, vector<int>(n + 1));
        vis.resize(n + 1);
        child.resize(n + 1);
        int ans = 0;
        FOR(u, 1, n) {
            FOR(i, 1, n) vis[i] = 0, child[i] = 1;
            dfs(u, u);
            int cnt = 0;
            FOR(v, 1, n) {
                if (v == u) continue;
                cnt += (a[u][v] > 0);
            }
            ans += cnt * (cnt - 1);
            FORALL(v, adj[u]) ans -= child[v] * (child[v] - 1);
        }
        cout << ans << '\n';
    }
}

namespace subtask5 {

    void main() {


    }
}

int main() {
    fastio;

    cin >> n >> m;
    adj.resize(n + 1);
    REP(i, m) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    FOR(u, 1, n) {
        sort(adj[u].begin(), adj[u].end());
        adj[u].resize(unique(adj[u].begin(), adj[u].end()) - adj[u].begin());
    }
    if (n <= 10 && m <= 100) subtask1::main();
    else if (n <= 50 && m <= 100) subtask2::main();
    else if (checkSub3()) subtask3::main();
    else if (checkSub45()) {
        if (n <= 1000) subtask4::main();
        else subtask5::main();
    }
    return 0;
}

Compilation message

count_triplets.cpp: In function 'void subtask1::main()':
count_triplets.cpp:41:35: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   41 |                         if (BIT(v - 1, mask)) continue;
      |                                 ~~^~~
count_triplets.cpp:7:26: note: in definition of macro 'BIT'
    7 | #define BIT(i, x) ((x >> i) & 1)
      |                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Incorrect 1 ms 344 KB Output isn't correct
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 10836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 4440 KB Output is correct
2 Correct 11 ms 4444 KB Output is correct
3 Correct 10 ms 4444 KB Output is correct
4 Correct 16 ms 4440 KB Output is correct
5 Correct 14 ms 4440 KB Output is correct
6 Correct 12 ms 4440 KB Output is correct
7 Correct 15 ms 4444 KB Output is correct
8 Correct 13 ms 4440 KB Output is correct
9 Correct 12 ms 4508 KB Output is correct
10 Correct 9 ms 4440 KB Output is correct
11 Correct 9 ms 4440 KB Output is correct
12 Correct 6 ms 4440 KB Output is correct
13 Correct 5 ms 4440 KB Output is correct
14 Correct 4 ms 4440 KB Output is correct
15 Correct 4 ms 4440 KB Output is correct
16 Correct 3 ms 4444 KB Output is correct
17 Correct 9 ms 4440 KB Output is correct
18 Correct 8 ms 4304 KB Output is correct
19 Correct 9 ms 4440 KB Output is correct
20 Correct 8 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 6224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 4440 KB Output is correct
2 Correct 11 ms 4440 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 6224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Incorrect 1 ms 344 KB Output isn't correct
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Incorrect 1 ms 344 KB Output isn't correct
37 Halted 0 ms 0 KB -