Submission #418376

# Submission time Handle Problem Language Result Execution time Memory
418376 2021-06-05T10:26:07 Z ACmachine Amusement Park (CEOI19_amusementpark) C++17
42 / 100
3000 ms 162208 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l))
#define FORD(i, j, k, l) for(int i = (j); i >= (k); i -= (l))
#define REP(i, n) FOR(i, 0, n, 1)
#define REPD(i, n) FORD(i, n, 0, 1)
#define pb push_back
typedef long long ll;
const int INF = (int)1e9;
const ll INFF = (ll)1e18;
const ll mod = 998244353;
mt19937_64 rng(time(NULL));
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<array<int, 2>> edges;
    vector<ll> random(m, 0);
    REP(i, m){
        int u, v;
        cin >> u >> v;
        u--; v--;
        edges.pb({u, v});
        random[i] = rng();
    }
    unordered_set<ll> uset;
    vector<int> order(n);
    iota(order.begin(), order.end(), 0);
    vector<int> pos(n, 0);
    ll ans = 0;
    do{
        REP(i, n){
            pos[order[i]] = i;
        }
        ll hsh = 0; int cost = 0;
        REP(i, edges.size()){
            auto e = edges[i];
            if(pos[e[0]] > pos[e[1]]){
                hsh += random[i];
                cost++;
            }
        }
        if(uset.find(hsh) != uset.end())
            continue;
        uset.insert(hsh);
        ans += cost;
        if(ans >= mod)
            ans -= mod;
    }while(next_permutation(order.begin(), order.end()));
    cout << ans << "\n";
    return 0;
}

Compilation message

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:3:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l))
      |                                            ^
amusementpark.cpp:5:19: note: in expansion of macro 'FOR'
    5 | #define REP(i, n) FOR(i, 0, n, 1)
      |                   ^~~
amusementpark.cpp:37:9: note: in expansion of macro 'REP'
   37 |         REP(i, edges.size()){
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 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 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 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 316 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 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 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 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 316 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 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 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 316 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 204 KB Output is correct
33 Correct 3 ms 204 KB Output is correct
34 Correct 4 ms 348 KB Output is correct
35 Correct 5 ms 460 KB Output is correct
36 Correct 7 ms 844 KB Output is correct
37 Correct 11 ms 1360 KB Output is correct
38 Correct 13 ms 1832 KB Output is correct
39 Correct 17 ms 204 KB Output is correct
40 Correct 22 ms 320 KB Output is correct
41 Correct 26 ms 356 KB Output is correct
42 Correct 39 ms 584 KB Output is correct
43 Correct 45 ms 1620 KB Output is correct
44 Correct 56 ms 2592 KB Output is correct
45 Correct 81 ms 5288 KB Output is correct
46 Correct 119 ms 10084 KB Output is correct
47 Correct 202 ms 19504 KB Output is correct
48 Correct 21 ms 204 KB Output is correct
49 Correct 31 ms 448 KB Output is correct
50 Correct 30 ms 460 KB Output is correct
51 Correct 30 ms 460 KB Output is correct
52 Correct 191 ms 292 KB Output is correct
53 Correct 229 ms 336 KB Output is correct
54 Correct 287 ms 576 KB Output is correct
55 Correct 370 ms 1564 KB Output is correct
56 Correct 486 ms 9864 KB Output is correct
57 Correct 714 ms 20780 KB Output is correct
58 Correct 1133 ms 43680 KB Output is correct
59 Correct 1807 ms 86368 KB Output is correct
60 Correct 2884 ms 162208 KB Output is correct
61 Correct 213 ms 324 KB Output is correct
62 Correct 318 ms 872 KB Output is correct
63 Correct 309 ms 832 KB Output is correct
64 Correct 309 ms 868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 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 316 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 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 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 316 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 204 KB Output is correct
33 Correct 3 ms 204 KB Output is correct
34 Correct 4 ms 348 KB Output is correct
35 Correct 5 ms 460 KB Output is correct
36 Correct 7 ms 844 KB Output is correct
37 Correct 11 ms 1360 KB Output is correct
38 Correct 13 ms 1832 KB Output is correct
39 Correct 17 ms 204 KB Output is correct
40 Correct 22 ms 320 KB Output is correct
41 Correct 26 ms 356 KB Output is correct
42 Correct 39 ms 584 KB Output is correct
43 Correct 45 ms 1620 KB Output is correct
44 Correct 56 ms 2592 KB Output is correct
45 Correct 81 ms 5288 KB Output is correct
46 Correct 119 ms 10084 KB Output is correct
47 Correct 202 ms 19504 KB Output is correct
48 Correct 21 ms 204 KB Output is correct
49 Correct 31 ms 448 KB Output is correct
50 Correct 30 ms 460 KB Output is correct
51 Correct 30 ms 460 KB Output is correct
52 Correct 191 ms 292 KB Output is correct
53 Correct 229 ms 336 KB Output is correct
54 Correct 287 ms 576 KB Output is correct
55 Correct 370 ms 1564 KB Output is correct
56 Correct 486 ms 9864 KB Output is correct
57 Correct 714 ms 20780 KB Output is correct
58 Correct 1133 ms 43680 KB Output is correct
59 Correct 1807 ms 86368 KB Output is correct
60 Correct 2884 ms 162208 KB Output is correct
61 Correct 213 ms 324 KB Output is correct
62 Correct 318 ms 872 KB Output is correct
63 Correct 309 ms 832 KB Output is correct
64 Correct 309 ms 868 KB Output is correct
65 Execution timed out 3043 ms 6440 KB Time limit exceeded
66 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 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 316 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 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 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 316 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 316 KB Output is correct
30 Correct 2 ms 332 KB Output is correct
31 Correct 2 ms 460 KB Output is correct
32 Correct 2 ms 204 KB Output is correct
33 Correct 3 ms 204 KB Output is correct
34 Correct 4 ms 348 KB Output is correct
35 Correct 5 ms 460 KB Output is correct
36 Correct 7 ms 844 KB Output is correct
37 Correct 11 ms 1360 KB Output is correct
38 Correct 13 ms 1832 KB Output is correct
39 Correct 17 ms 204 KB Output is correct
40 Correct 22 ms 320 KB Output is correct
41 Correct 26 ms 356 KB Output is correct
42 Correct 39 ms 584 KB Output is correct
43 Correct 45 ms 1620 KB Output is correct
44 Correct 56 ms 2592 KB Output is correct
45 Correct 81 ms 5288 KB Output is correct
46 Correct 119 ms 10084 KB Output is correct
47 Correct 202 ms 19504 KB Output is correct
48 Correct 21 ms 204 KB Output is correct
49 Correct 31 ms 448 KB Output is correct
50 Correct 30 ms 460 KB Output is correct
51 Correct 30 ms 460 KB Output is correct
52 Correct 191 ms 292 KB Output is correct
53 Correct 229 ms 336 KB Output is correct
54 Correct 287 ms 576 KB Output is correct
55 Correct 370 ms 1564 KB Output is correct
56 Correct 486 ms 9864 KB Output is correct
57 Correct 714 ms 20780 KB Output is correct
58 Correct 1133 ms 43680 KB Output is correct
59 Correct 1807 ms 86368 KB Output is correct
60 Correct 2884 ms 162208 KB Output is correct
61 Correct 213 ms 324 KB Output is correct
62 Correct 318 ms 872 KB Output is correct
63 Correct 309 ms 832 KB Output is correct
64 Correct 309 ms 868 KB Output is correct
65 Execution timed out 3043 ms 6440 KB Time limit exceeded
66 Halted 0 ms 0 KB -