Submission #1111033

# Submission time Handle Problem Language Result Execution time Memory
1111033 2024-11-11T10:50:37 Z crafticat Amusement Park (CEOI19_amusementpark) C++17
42 / 100
3000 ms 588 KB
#include <bits/stdc++.h>

using namespace std;

template<typename T>
using V = vector<T>;
using vi = V<int>;
using vb = V<bool>;
using pi = pair<int,int>;

#define F0R(i,n) for (int i = 0; i < n;i++)
#define FOR(i, j, n) for(int i = j; i < n;i++)
#define ckmin(x,y) x = min(x,y)
#define f first
#define s second
using ll = long long;
constexpr int MOD = 998244353;

V<int> vis;
V<V<int>> g;

bool dfs(int x) {
    if (vis[x] == 1) return false;
    vis[x] = 1;
    for (auto y : g[x]) {
        if (vis[y] == 2) continue;
        if (!dfs(y)) return false;
    }

    vis[x] = 2;
    return true;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int n, m; cin >> n >> m;
    V<pi> edges(m);
    set<pi> exists;

    F0R(i, m) {
        int x, y; cin >> x >> y;
        x--;
        y--;
        edges[i] = {x,y};
        exists.insert({x,y});
        exists.insert({y,x});
    }

    ll ans = 0;
    vi perm(n); // Height of I
    F0R(i, n)
        perm[i] = i;

    do {
        int cost = 0;
        for (auto [a,b] : edges) {
            if (perm[a] > perm[b]) cost++;
        }
        bool pos = true;
        V<pi> check;
        F0R(i, n) {
            check.emplace_back(perm[i],i);
        }
        std::sort(check.begin(), check.end());

        F0R(i, n - 1) {
            int a = check[i].s;
            for (int j = i + 1; j < n; ++j) {
                int b = check[j].s;
                if (exists.count({a,b})) break;
                if (a > b) pos = false;
            }
        }
        if (pos)
            ans += cost;

        ans %= MOD;
    } while (std::next_permutation(perm.begin(), perm.end()));

    cout << ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 524 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 508 KB Output is correct
6 Correct 1 ms 380 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 524 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 508 KB Output is correct
6 Correct 1 ms 380 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 508 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 456 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 524 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 508 KB Output is correct
6 Correct 1 ms 380 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 508 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 456 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 2 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 2 ms 336 KB Output is correct
30 Correct 2 ms 336 KB Output is correct
31 Correct 2 ms 336 KB Output is correct
32 Correct 14 ms 336 KB Output is correct
33 Correct 14 ms 504 KB Output is correct
34 Correct 13 ms 336 KB Output is correct
35 Correct 14 ms 456 KB Output is correct
36 Correct 14 ms 464 KB Output is correct
37 Correct 13 ms 336 KB Output is correct
38 Correct 14 ms 336 KB Output is correct
39 Correct 126 ms 336 KB Output is correct
40 Correct 144 ms 588 KB Output is correct
41 Correct 136 ms 336 KB Output is correct
42 Correct 143 ms 336 KB Output is correct
43 Correct 130 ms 336 KB Output is correct
44 Correct 139 ms 336 KB Output is correct
45 Correct 130 ms 336 KB Output is correct
46 Correct 131 ms 336 KB Output is correct
47 Correct 130 ms 336 KB Output is correct
48 Correct 131 ms 336 KB Output is correct
49 Correct 129 ms 336 KB Output is correct
50 Correct 132 ms 336 KB Output is correct
51 Correct 136 ms 336 KB Output is correct
52 Correct 1389 ms 444 KB Output is correct
53 Correct 1529 ms 440 KB Output is correct
54 Correct 1544 ms 448 KB Output is correct
55 Correct 1462 ms 448 KB Output is correct
56 Correct 1436 ms 336 KB Output is correct
57 Correct 1415 ms 452 KB Output is correct
58 Correct 1439 ms 336 KB Output is correct
59 Correct 1411 ms 452 KB Output is correct
60 Correct 1428 ms 448 KB Output is correct
61 Correct 1479 ms 440 KB Output is correct
62 Correct 1437 ms 444 KB Output is correct
63 Correct 1536 ms 448 KB Output is correct
64 Correct 1571 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 524 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 508 KB Output is correct
6 Correct 1 ms 380 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 508 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 456 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 2 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 2 ms 336 KB Output is correct
30 Correct 2 ms 336 KB Output is correct
31 Correct 2 ms 336 KB Output is correct
32 Correct 14 ms 336 KB Output is correct
33 Correct 14 ms 504 KB Output is correct
34 Correct 13 ms 336 KB Output is correct
35 Correct 14 ms 456 KB Output is correct
36 Correct 14 ms 464 KB Output is correct
37 Correct 13 ms 336 KB Output is correct
38 Correct 14 ms 336 KB Output is correct
39 Correct 126 ms 336 KB Output is correct
40 Correct 144 ms 588 KB Output is correct
41 Correct 136 ms 336 KB Output is correct
42 Correct 143 ms 336 KB Output is correct
43 Correct 130 ms 336 KB Output is correct
44 Correct 139 ms 336 KB Output is correct
45 Correct 130 ms 336 KB Output is correct
46 Correct 131 ms 336 KB Output is correct
47 Correct 130 ms 336 KB Output is correct
48 Correct 131 ms 336 KB Output is correct
49 Correct 129 ms 336 KB Output is correct
50 Correct 132 ms 336 KB Output is correct
51 Correct 136 ms 336 KB Output is correct
52 Correct 1389 ms 444 KB Output is correct
53 Correct 1529 ms 440 KB Output is correct
54 Correct 1544 ms 448 KB Output is correct
55 Correct 1462 ms 448 KB Output is correct
56 Correct 1436 ms 336 KB Output is correct
57 Correct 1415 ms 452 KB Output is correct
58 Correct 1439 ms 336 KB Output is correct
59 Correct 1411 ms 452 KB Output is correct
60 Correct 1428 ms 448 KB Output is correct
61 Correct 1479 ms 440 KB Output is correct
62 Correct 1437 ms 444 KB Output is correct
63 Correct 1536 ms 448 KB Output is correct
64 Correct 1571 ms 452 KB Output is correct
65 Execution timed out 3059 ms 336 KB Time limit exceeded
66 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 524 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 508 KB Output is correct
6 Correct 1 ms 380 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 508 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 456 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 2 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 2 ms 336 KB Output is correct
30 Correct 2 ms 336 KB Output is correct
31 Correct 2 ms 336 KB Output is correct
32 Correct 14 ms 336 KB Output is correct
33 Correct 14 ms 504 KB Output is correct
34 Correct 13 ms 336 KB Output is correct
35 Correct 14 ms 456 KB Output is correct
36 Correct 14 ms 464 KB Output is correct
37 Correct 13 ms 336 KB Output is correct
38 Correct 14 ms 336 KB Output is correct
39 Correct 126 ms 336 KB Output is correct
40 Correct 144 ms 588 KB Output is correct
41 Correct 136 ms 336 KB Output is correct
42 Correct 143 ms 336 KB Output is correct
43 Correct 130 ms 336 KB Output is correct
44 Correct 139 ms 336 KB Output is correct
45 Correct 130 ms 336 KB Output is correct
46 Correct 131 ms 336 KB Output is correct
47 Correct 130 ms 336 KB Output is correct
48 Correct 131 ms 336 KB Output is correct
49 Correct 129 ms 336 KB Output is correct
50 Correct 132 ms 336 KB Output is correct
51 Correct 136 ms 336 KB Output is correct
52 Correct 1389 ms 444 KB Output is correct
53 Correct 1529 ms 440 KB Output is correct
54 Correct 1544 ms 448 KB Output is correct
55 Correct 1462 ms 448 KB Output is correct
56 Correct 1436 ms 336 KB Output is correct
57 Correct 1415 ms 452 KB Output is correct
58 Correct 1439 ms 336 KB Output is correct
59 Correct 1411 ms 452 KB Output is correct
60 Correct 1428 ms 448 KB Output is correct
61 Correct 1479 ms 440 KB Output is correct
62 Correct 1437 ms 444 KB Output is correct
63 Correct 1536 ms 448 KB Output is correct
64 Correct 1571 ms 452 KB Output is correct
65 Execution timed out 3059 ms 336 KB Time limit exceeded
66 Halted 0 ms 0 KB -