// In the name of God
// Hope is last to die
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define int long long
#define S second
#define F first
#define mp make_pair
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define all(x) (x).begin(), (x).end()
#define len(x) ((int)(x).size())
const int maxn = 11;
const int inf = 1e9 + 7, mod = 998244353;
int n, m, in[maxn], deg[maxn];
vector<int> adj[maxn], g[maxn];
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
set<int> st;
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 0; i < m; i++){
int u, v; cin >> u >> v;
adj[u].pb(v);
}
vector<int> A;
do{
for(int i = 0; i < n; i++){
in[a[i]] = i;
deg[i + 1] = 0;
g[i + 1].clear();
}
for(int i = 1; i <= n; i++){
for(auto u: adj[i]){
if(in[i] > in[u]){
g[u].pb(i);
deg[i]++;
}
else{
g[i].pb(u);
deg[u]++;
}
}
}
for(int i = 1; i <= n; i++) if(!deg[i]) st.insert(i);
int x = 0;
while(st.size()){
int v = (*st.begin());
x *= 10;
x += v - 1;
st.erase(st.begin());
for(auto u: g[v]){
deg[u]--;
if(!deg[u]) st.insert(u);
}
}
A.pb(x);
} while (next_permutation(a, a + n));
sort(all(A));
A.resize(unique(all(A)) - A.begin());
ll ans = 0;
for(auto &per: A){
for(int i = 0; i < n; i++){
in[per % 10 + 1] = n - i;
per /= 10;
}
for(int i = 1; i <= n; i++){
for(auto u: adj[i]) if(in[u] < in[i]) ans++;
}
}
cout << ((ans) % mod) << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 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 |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
460 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 |
1 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 |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
2 ms |
344 KB |
Output is correct |
27 |
Correct |
3 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
348 KB |
Output is correct |
30 |
Correct |
3 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
348 KB |
Output is correct |
32 |
Correct |
14 ms |
1228 KB |
Output is correct |
33 |
Correct |
15 ms |
992 KB |
Output is correct |
34 |
Correct |
17 ms |
868 KB |
Output is correct |
35 |
Correct |
17 ms |
1004 KB |
Output is correct |
36 |
Correct |
19 ms |
988 KB |
Output is correct |
37 |
Correct |
26 ms |
992 KB |
Output is correct |
38 |
Correct |
22 ms |
992 KB |
Output is correct |
39 |
Correct |
140 ms |
4808 KB |
Output is correct |
40 |
Correct |
150 ms |
5100 KB |
Output is correct |
41 |
Correct |
153 ms |
4996 KB |
Output is correct |
42 |
Correct |
170 ms |
4808 KB |
Output is correct |
43 |
Correct |
173 ms |
5352 KB |
Output is correct |
44 |
Correct |
177 ms |
5572 KB |
Output is correct |
45 |
Correct |
188 ms |
5116 KB |
Output is correct |
46 |
Correct |
213 ms |
5916 KB |
Output is correct |
47 |
Correct |
217 ms |
5320 KB |
Output is correct |
48 |
Correct |
147 ms |
4764 KB |
Output is correct |
49 |
Correct |
189 ms |
6644 KB |
Output is correct |
50 |
Correct |
158 ms |
5064 KB |
Output is correct |
51 |
Correct |
156 ms |
5172 KB |
Output is correct |
52 |
Correct |
1604 ms |
34320 KB |
Output is correct |
53 |
Correct |
1634 ms |
33936 KB |
Output is correct |
54 |
Correct |
1710 ms |
34360 KB |
Output is correct |
55 |
Correct |
1776 ms |
35208 KB |
Output is correct |
56 |
Correct |
1921 ms |
34220 KB |
Output is correct |
57 |
Correct |
1968 ms |
34224 KB |
Output is correct |
58 |
Correct |
2119 ms |
35400 KB |
Output is correct |
59 |
Correct |
2251 ms |
34304 KB |
Output is correct |
60 |
Correct |
2403 ms |
35036 KB |
Output is correct |
61 |
Correct |
1658 ms |
33696 KB |
Output is correct |
62 |
Correct |
1713 ms |
34348 KB |
Output is correct |
63 |
Correct |
1712 ms |
34468 KB |
Output is correct |
64 |
Correct |
1763 ms |
34276 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 |
1 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 |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
2 ms |
344 KB |
Output is correct |
27 |
Correct |
3 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
348 KB |
Output is correct |
30 |
Correct |
3 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
348 KB |
Output is correct |
32 |
Correct |
14 ms |
1228 KB |
Output is correct |
33 |
Correct |
15 ms |
992 KB |
Output is correct |
34 |
Correct |
17 ms |
868 KB |
Output is correct |
35 |
Correct |
17 ms |
1004 KB |
Output is correct |
36 |
Correct |
19 ms |
988 KB |
Output is correct |
37 |
Correct |
26 ms |
992 KB |
Output is correct |
38 |
Correct |
22 ms |
992 KB |
Output is correct |
39 |
Correct |
140 ms |
4808 KB |
Output is correct |
40 |
Correct |
150 ms |
5100 KB |
Output is correct |
41 |
Correct |
153 ms |
4996 KB |
Output is correct |
42 |
Correct |
170 ms |
4808 KB |
Output is correct |
43 |
Correct |
173 ms |
5352 KB |
Output is correct |
44 |
Correct |
177 ms |
5572 KB |
Output is correct |
45 |
Correct |
188 ms |
5116 KB |
Output is correct |
46 |
Correct |
213 ms |
5916 KB |
Output is correct |
47 |
Correct |
217 ms |
5320 KB |
Output is correct |
48 |
Correct |
147 ms |
4764 KB |
Output is correct |
49 |
Correct |
189 ms |
6644 KB |
Output is correct |
50 |
Correct |
158 ms |
5064 KB |
Output is correct |
51 |
Correct |
156 ms |
5172 KB |
Output is correct |
52 |
Correct |
1604 ms |
34320 KB |
Output is correct |
53 |
Correct |
1634 ms |
33936 KB |
Output is correct |
54 |
Correct |
1710 ms |
34360 KB |
Output is correct |
55 |
Correct |
1776 ms |
35208 KB |
Output is correct |
56 |
Correct |
1921 ms |
34220 KB |
Output is correct |
57 |
Correct |
1968 ms |
34224 KB |
Output is correct |
58 |
Correct |
2119 ms |
35400 KB |
Output is correct |
59 |
Correct |
2251 ms |
34304 KB |
Output is correct |
60 |
Correct |
2403 ms |
35036 KB |
Output is correct |
61 |
Correct |
1658 ms |
33696 KB |
Output is correct |
62 |
Correct |
1713 ms |
34348 KB |
Output is correct |
63 |
Correct |
1712 ms |
34468 KB |
Output is correct |
64 |
Correct |
1763 ms |
34276 KB |
Output is correct |
65 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
66 |
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 |
1 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 |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
344 KB |
Output is correct |
26 |
Correct |
2 ms |
344 KB |
Output is correct |
27 |
Correct |
3 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
348 KB |
Output is correct |
30 |
Correct |
3 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
348 KB |
Output is correct |
32 |
Correct |
14 ms |
1228 KB |
Output is correct |
33 |
Correct |
15 ms |
992 KB |
Output is correct |
34 |
Correct |
17 ms |
868 KB |
Output is correct |
35 |
Correct |
17 ms |
1004 KB |
Output is correct |
36 |
Correct |
19 ms |
988 KB |
Output is correct |
37 |
Correct |
26 ms |
992 KB |
Output is correct |
38 |
Correct |
22 ms |
992 KB |
Output is correct |
39 |
Correct |
140 ms |
4808 KB |
Output is correct |
40 |
Correct |
150 ms |
5100 KB |
Output is correct |
41 |
Correct |
153 ms |
4996 KB |
Output is correct |
42 |
Correct |
170 ms |
4808 KB |
Output is correct |
43 |
Correct |
173 ms |
5352 KB |
Output is correct |
44 |
Correct |
177 ms |
5572 KB |
Output is correct |
45 |
Correct |
188 ms |
5116 KB |
Output is correct |
46 |
Correct |
213 ms |
5916 KB |
Output is correct |
47 |
Correct |
217 ms |
5320 KB |
Output is correct |
48 |
Correct |
147 ms |
4764 KB |
Output is correct |
49 |
Correct |
189 ms |
6644 KB |
Output is correct |
50 |
Correct |
158 ms |
5064 KB |
Output is correct |
51 |
Correct |
156 ms |
5172 KB |
Output is correct |
52 |
Correct |
1604 ms |
34320 KB |
Output is correct |
53 |
Correct |
1634 ms |
33936 KB |
Output is correct |
54 |
Correct |
1710 ms |
34360 KB |
Output is correct |
55 |
Correct |
1776 ms |
35208 KB |
Output is correct |
56 |
Correct |
1921 ms |
34220 KB |
Output is correct |
57 |
Correct |
1968 ms |
34224 KB |
Output is correct |
58 |
Correct |
2119 ms |
35400 KB |
Output is correct |
59 |
Correct |
2251 ms |
34304 KB |
Output is correct |
60 |
Correct |
2403 ms |
35036 KB |
Output is correct |
61 |
Correct |
1658 ms |
33696 KB |
Output is correct |
62 |
Correct |
1713 ms |
34348 KB |
Output is correct |
63 |
Correct |
1712 ms |
34468 KB |
Output is correct |
64 |
Correct |
1763 ms |
34276 KB |
Output is correct |
65 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
66 |
Halted |
0 ms |
0 KB |
- |