답안 #502531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
502531 2022-01-06T08:10:06 Z InternetPerson10 Amusement Park (CEOI19_amusementpark) C++17
19 / 100
3000 ms 324 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

bool bad[20][20];

const ll MOD = 998244353;

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> edges(m);
    for(int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        edges[i] = {x, y};
        bad[y][x] = true;
    }
    ll ans = 0;
    vector<int> nums(n);
    for(int i = 0; i < n; i++) nums[i] = i;
    for(int i = 0; i < (1 << m); i++) {
        vector<vector<int>> adj(n);
        for(int j = 0; j < m; j++) {
            if(i & (1 << j)) swap(edges[j].first, edges[j].second);
            adj[edges[j].first].push_back(edges[j].second);
        }
        bool ok = true;
        queue<int> q;
        vector<bool> done(n);
        for(int j = 0; j < n; j++) {
            if(adj[j].size() == 0) {
                q.push(j);
                done[j] = true;
            }
        }
        while(q.size()) {
            int p = q.front(); q.pop();
            for(int j = 0; j < n; j++) {
                for(int k = 0; k < adj[j].size(); k++) {
                    if(adj[j][k] == p) {
                        adj[j].erase(adj[j].begin() + k);
                        break;
                    }
                }
                if(adj[j].size() == 0 && !done[j]) {
                    q.push(j);
                    done[j] = true;
                }
            }
        }
        int g = 0;
        for(int j = 0; j < n; j++) {
            if(!done[j]) ok = false;
        }
        for(int j = 0; j < m; j++) {
            if(i & (1 << j)) {
                swap(edges[j].first, edges[j].second);
                g++;
            }
        }
        if(ok) ans += g;
    }
    cout << ans << '\n';
}

Compilation message

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:42:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |                 for(int k = 0; k < adj[j].size(); k++) {
      |                                ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 272 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 288 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 272 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 288 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 272 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 292 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 292 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 288 KB Output is correct
23 Correct 3 ms 204 KB Output is correct
24 Correct 24 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 272 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 288 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 272 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 292 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 292 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 288 KB Output is correct
23 Correct 3 ms 204 KB Output is correct
24 Correct 24 ms 204 KB Output is correct
25 Correct 1 ms 292 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 3 ms 204 KB Output is correct
29 Correct 28 ms 268 KB Output is correct
30 Correct 225 ms 268 KB Output is correct
31 Correct 2016 ms 276 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 292 KB Output is correct
34 Correct 5 ms 288 KB Output is correct
35 Correct 59 ms 280 KB Output is correct
36 Correct 989 ms 324 KB Output is correct
37 Execution timed out 3062 ms 204 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 272 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 288 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 272 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 292 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 292 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 288 KB Output is correct
23 Correct 3 ms 204 KB Output is correct
24 Correct 24 ms 204 KB Output is correct
25 Correct 1 ms 292 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 3 ms 204 KB Output is correct
29 Correct 28 ms 268 KB Output is correct
30 Correct 225 ms 268 KB Output is correct
31 Correct 2016 ms 276 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 292 KB Output is correct
34 Correct 5 ms 288 KB Output is correct
35 Correct 59 ms 280 KB Output is correct
36 Correct 989 ms 324 KB Output is correct
37 Execution timed out 3062 ms 204 KB Time limit exceeded
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 272 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 288 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 272 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 292 KB Output is correct
12 Correct 1 ms 292 KB Output is correct
13 Correct 1 ms 292 KB Output is correct
14 Correct 1 ms 288 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 288 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 288 KB Output is correct
23 Correct 3 ms 204 KB Output is correct
24 Correct 24 ms 204 KB Output is correct
25 Correct 1 ms 292 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 3 ms 204 KB Output is correct
29 Correct 28 ms 268 KB Output is correct
30 Correct 225 ms 268 KB Output is correct
31 Correct 2016 ms 276 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 292 KB Output is correct
34 Correct 5 ms 288 KB Output is correct
35 Correct 59 ms 280 KB Output is correct
36 Correct 989 ms 324 KB Output is correct
37 Execution timed out 3062 ms 204 KB Time limit exceeded
38 Halted 0 ms 0 KB -