#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];
const ii mod = {1e9+7,998244353};
const ii base = {311,113};
ii operator + (const ii &a,const ii &b){
return {(a.fi + b.fi) % mod.fi, (a.se + b.se) % mod.se};
}
ii operator - (const ii &a,const ii &b){
return {((a.se - b.fi) % mod.fi + mod.fi)%mod.fi,((a.se - b.fi) % mod.se + mod.se)%mod.se};
}
ii operator * (const ii &a,const ii &b){
return {(a.fi * b.fi) % mod.fi, (a.se * b.se) % mod.se};
}
struct hash_pair {
template <class T1, class T2>
size_t operator()(const pair<T1, T2>& p) const
{
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
if (hash1 != hash2) {
return hash1 ^ hash2;
}
// If hash1 == hash2, their XOR is zero.
return hash1;
}
};
unordered_map<ii,bool,hash_pair> hashcode;
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;
ii code = {0,0};
for(int i=1;i<=m;i++){
if (pos[edge[i].fi] > pos[edge[i].se]) {
cost++;
code = (code * base + ii(3,2));
}
else{
code = (code * base + ii(2,1));
}
}
if (hashcode[code] == 0){
ans = (ans + cost) % MOD;
hashcode[code] = 1;
}
}while(next_permutation(permutation+1,permutation+1+n));
cout<<ans<<endl;
}
Compilation message
amusementpark.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
52 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
5 ms |
348 KB |
Output is correct |
35 |
Correct |
6 ms |
556 KB |
Output is correct |
36 |
Correct |
9 ms |
1116 KB |
Output is correct |
37 |
Correct |
11 ms |
1840 KB |
Output is correct |
38 |
Correct |
13 ms |
2488 KB |
Output is correct |
39 |
Correct |
15 ms |
348 KB |
Output is correct |
40 |
Correct |
24 ms |
472 KB |
Output is correct |
41 |
Correct |
35 ms |
348 KB |
Output is correct |
42 |
Correct |
47 ms |
784 KB |
Output is correct |
43 |
Correct |
60 ms |
2112 KB |
Output is correct |
44 |
Correct |
75 ms |
3424 KB |
Output is correct |
45 |
Correct |
94 ms |
7280 KB |
Output is correct |
46 |
Correct |
125 ms |
13744 KB |
Output is correct |
47 |
Correct |
182 ms |
25068 KB |
Output is correct |
48 |
Correct |
24 ms |
344 KB |
Output is correct |
49 |
Correct |
45 ms |
600 KB |
Output is correct |
50 |
Correct |
44 ms |
676 KB |
Output is correct |
51 |
Correct |
43 ms |
600 KB |
Output is correct |
52 |
Correct |
165 ms |
348 KB |
Output is correct |
53 |
Correct |
294 ms |
596 KB |
Output is correct |
54 |
Correct |
417 ms |
820 KB |
Output is correct |
55 |
Correct |
557 ms |
2176 KB |
Output is correct |
56 |
Correct |
726 ms |
12736 KB |
Output is correct |
57 |
Correct |
1000 ms |
28352 KB |
Output is correct |
58 |
Correct |
1362 ms |
59928 KB |
Output is correct |
59 |
Correct |
2047 ms |
117664 KB |
Output is correct |
60 |
Execution timed out |
3062 ms |
217544 KB |
Time limit exceeded |
61 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
5 ms |
348 KB |
Output is correct |
35 |
Correct |
6 ms |
556 KB |
Output is correct |
36 |
Correct |
9 ms |
1116 KB |
Output is correct |
37 |
Correct |
11 ms |
1840 KB |
Output is correct |
38 |
Correct |
13 ms |
2488 KB |
Output is correct |
39 |
Correct |
15 ms |
348 KB |
Output is correct |
40 |
Correct |
24 ms |
472 KB |
Output is correct |
41 |
Correct |
35 ms |
348 KB |
Output is correct |
42 |
Correct |
47 ms |
784 KB |
Output is correct |
43 |
Correct |
60 ms |
2112 KB |
Output is correct |
44 |
Correct |
75 ms |
3424 KB |
Output is correct |
45 |
Correct |
94 ms |
7280 KB |
Output is correct |
46 |
Correct |
125 ms |
13744 KB |
Output is correct |
47 |
Correct |
182 ms |
25068 KB |
Output is correct |
48 |
Correct |
24 ms |
344 KB |
Output is correct |
49 |
Correct |
45 ms |
600 KB |
Output is correct |
50 |
Correct |
44 ms |
676 KB |
Output is correct |
51 |
Correct |
43 ms |
600 KB |
Output is correct |
52 |
Correct |
165 ms |
348 KB |
Output is correct |
53 |
Correct |
294 ms |
596 KB |
Output is correct |
54 |
Correct |
417 ms |
820 KB |
Output is correct |
55 |
Correct |
557 ms |
2176 KB |
Output is correct |
56 |
Correct |
726 ms |
12736 KB |
Output is correct |
57 |
Correct |
1000 ms |
28352 KB |
Output is correct |
58 |
Correct |
1362 ms |
59928 KB |
Output is correct |
59 |
Correct |
2047 ms |
117664 KB |
Output is correct |
60 |
Execution timed out |
3062 ms |
217544 KB |
Time limit exceeded |
61 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
2 ms |
604 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
3 ms |
348 KB |
Output is correct |
34 |
Correct |
5 ms |
348 KB |
Output is correct |
35 |
Correct |
6 ms |
556 KB |
Output is correct |
36 |
Correct |
9 ms |
1116 KB |
Output is correct |
37 |
Correct |
11 ms |
1840 KB |
Output is correct |
38 |
Correct |
13 ms |
2488 KB |
Output is correct |
39 |
Correct |
15 ms |
348 KB |
Output is correct |
40 |
Correct |
24 ms |
472 KB |
Output is correct |
41 |
Correct |
35 ms |
348 KB |
Output is correct |
42 |
Correct |
47 ms |
784 KB |
Output is correct |
43 |
Correct |
60 ms |
2112 KB |
Output is correct |
44 |
Correct |
75 ms |
3424 KB |
Output is correct |
45 |
Correct |
94 ms |
7280 KB |
Output is correct |
46 |
Correct |
125 ms |
13744 KB |
Output is correct |
47 |
Correct |
182 ms |
25068 KB |
Output is correct |
48 |
Correct |
24 ms |
344 KB |
Output is correct |
49 |
Correct |
45 ms |
600 KB |
Output is correct |
50 |
Correct |
44 ms |
676 KB |
Output is correct |
51 |
Correct |
43 ms |
600 KB |
Output is correct |
52 |
Correct |
165 ms |
348 KB |
Output is correct |
53 |
Correct |
294 ms |
596 KB |
Output is correct |
54 |
Correct |
417 ms |
820 KB |
Output is correct |
55 |
Correct |
557 ms |
2176 KB |
Output is correct |
56 |
Correct |
726 ms |
12736 KB |
Output is correct |
57 |
Correct |
1000 ms |
28352 KB |
Output is correct |
58 |
Correct |
1362 ms |
59928 KB |
Output is correct |
59 |
Correct |
2047 ms |
117664 KB |
Output is correct |
60 |
Execution timed out |
3062 ms |
217544 KB |
Time limit exceeded |
61 |
Halted |
0 ms |
0 KB |
- |