#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 998244353
#define INF 1e18
#define fi first
#define se second
#define endl "\n"
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define pi 3.14159265359
#define TASKNAME "amusepark"
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
const int MAXN = 3e2 + 9;
ii edge[MAXN];
int n,m,ans=0;
int pos[MAXN];
map<int,int> hashcode;
set<int> st;
main()
{
fast;
// freopen(TASKNAME".inp","r",stdin);
// freopen(TASKNAME".out","w",stdout);
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>edge[i].fi>>edge[i].se;
}
int permutation[15];
string s;
iota(permutation+1,permutation+1+n,1);
do{
for(int i=1;i<=n;i++){
pos[permutation[i]] = i;
}
int cost = 0;
int code = 0;
for(int i=1;i<=m;i++){
if (pos[edge[i].fi] > pos[edge[i].se]) {
cost++;
code = code + (1LL<<(i-1));
}
}
if (st.insert(code).se == true){
ans = (ans + cost) % MOD;
hashcode[code] = 1;
}
}while(next_permutation(permutation+1,permutation+1+n));
cout<<ans<<endl;
}
Compilation message
amusementpark.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
27 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
860 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
5 ms |
860 KB |
Output is correct |
36 |
Correct |
8 ms |
1372 KB |
Output is correct |
37 |
Correct |
14 ms |
2828 KB |
Output is correct |
38 |
Correct |
16 ms |
4700 KB |
Output is correct |
39 |
Correct |
6 ms |
464 KB |
Output is correct |
40 |
Correct |
11 ms |
348 KB |
Output is correct |
41 |
Correct |
19 ms |
616 KB |
Output is correct |
42 |
Correct |
28 ms |
1028 KB |
Output is correct |
43 |
Correct |
42 ms |
3412 KB |
Output is correct |
44 |
Correct |
64 ms |
6232 KB |
Output is correct |
45 |
Correct |
82 ms |
13208 KB |
Output is correct |
46 |
Correct |
131 ms |
24916 KB |
Output is correct |
47 |
Correct |
185 ms |
40212 KB |
Output is correct |
48 |
Correct |
17 ms |
348 KB |
Output is correct |
49 |
Correct |
31 ms |
832 KB |
Output is correct |
50 |
Correct |
31 ms |
860 KB |
Output is correct |
51 |
Correct |
23 ms |
860 KB |
Output is correct |
52 |
Correct |
84 ms |
496 KB |
Output is correct |
53 |
Correct |
134 ms |
344 KB |
Output is correct |
54 |
Correct |
215 ms |
1104 KB |
Output is correct |
55 |
Correct |
301 ms |
3936 KB |
Output is correct |
56 |
Correct |
451 ms |
20168 KB |
Output is correct |
57 |
Correct |
666 ms |
52640 KB |
Output is correct |
58 |
Correct |
973 ms |
112956 KB |
Output is correct |
59 |
Correct |
1457 ms |
220820 KB |
Output is correct |
60 |
Correct |
2133 ms |
398236 KB |
Output is correct |
61 |
Correct |
130 ms |
344 KB |
Output is correct |
62 |
Correct |
238 ms |
1916 KB |
Output is correct |
63 |
Correct |
245 ms |
1764 KB |
Output is correct |
64 |
Correct |
255 ms |
1864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
860 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
5 ms |
860 KB |
Output is correct |
36 |
Correct |
8 ms |
1372 KB |
Output is correct |
37 |
Correct |
14 ms |
2828 KB |
Output is correct |
38 |
Correct |
16 ms |
4700 KB |
Output is correct |
39 |
Correct |
6 ms |
464 KB |
Output is correct |
40 |
Correct |
11 ms |
348 KB |
Output is correct |
41 |
Correct |
19 ms |
616 KB |
Output is correct |
42 |
Correct |
28 ms |
1028 KB |
Output is correct |
43 |
Correct |
42 ms |
3412 KB |
Output is correct |
44 |
Correct |
64 ms |
6232 KB |
Output is correct |
45 |
Correct |
82 ms |
13208 KB |
Output is correct |
46 |
Correct |
131 ms |
24916 KB |
Output is correct |
47 |
Correct |
185 ms |
40212 KB |
Output is correct |
48 |
Correct |
17 ms |
348 KB |
Output is correct |
49 |
Correct |
31 ms |
832 KB |
Output is correct |
50 |
Correct |
31 ms |
860 KB |
Output is correct |
51 |
Correct |
23 ms |
860 KB |
Output is correct |
52 |
Correct |
84 ms |
496 KB |
Output is correct |
53 |
Correct |
134 ms |
344 KB |
Output is correct |
54 |
Correct |
215 ms |
1104 KB |
Output is correct |
55 |
Correct |
301 ms |
3936 KB |
Output is correct |
56 |
Correct |
451 ms |
20168 KB |
Output is correct |
57 |
Correct |
666 ms |
52640 KB |
Output is correct |
58 |
Correct |
973 ms |
112956 KB |
Output is correct |
59 |
Correct |
1457 ms |
220820 KB |
Output is correct |
60 |
Correct |
2133 ms |
398236 KB |
Output is correct |
61 |
Correct |
130 ms |
344 KB |
Output is correct |
62 |
Correct |
238 ms |
1916 KB |
Output is correct |
63 |
Correct |
245 ms |
1764 KB |
Output is correct |
64 |
Correct |
255 ms |
1864 KB |
Output is correct |
65 |
Execution timed out |
3023 ms |
18352 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
860 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
5 ms |
860 KB |
Output is correct |
36 |
Correct |
8 ms |
1372 KB |
Output is correct |
37 |
Correct |
14 ms |
2828 KB |
Output is correct |
38 |
Correct |
16 ms |
4700 KB |
Output is correct |
39 |
Correct |
6 ms |
464 KB |
Output is correct |
40 |
Correct |
11 ms |
348 KB |
Output is correct |
41 |
Correct |
19 ms |
616 KB |
Output is correct |
42 |
Correct |
28 ms |
1028 KB |
Output is correct |
43 |
Correct |
42 ms |
3412 KB |
Output is correct |
44 |
Correct |
64 ms |
6232 KB |
Output is correct |
45 |
Correct |
82 ms |
13208 KB |
Output is correct |
46 |
Correct |
131 ms |
24916 KB |
Output is correct |
47 |
Correct |
185 ms |
40212 KB |
Output is correct |
48 |
Correct |
17 ms |
348 KB |
Output is correct |
49 |
Correct |
31 ms |
832 KB |
Output is correct |
50 |
Correct |
31 ms |
860 KB |
Output is correct |
51 |
Correct |
23 ms |
860 KB |
Output is correct |
52 |
Correct |
84 ms |
496 KB |
Output is correct |
53 |
Correct |
134 ms |
344 KB |
Output is correct |
54 |
Correct |
215 ms |
1104 KB |
Output is correct |
55 |
Correct |
301 ms |
3936 KB |
Output is correct |
56 |
Correct |
451 ms |
20168 KB |
Output is correct |
57 |
Correct |
666 ms |
52640 KB |
Output is correct |
58 |
Correct |
973 ms |
112956 KB |
Output is correct |
59 |
Correct |
1457 ms |
220820 KB |
Output is correct |
60 |
Correct |
2133 ms |
398236 KB |
Output is correct |
61 |
Correct |
130 ms |
344 KB |
Output is correct |
62 |
Correct |
238 ms |
1916 KB |
Output is correct |
63 |
Correct |
245 ms |
1764 KB |
Output is correct |
64 |
Correct |
255 ms |
1864 KB |
Output is correct |
65 |
Execution timed out |
3023 ms |
18352 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |