// 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 = 1; i <= 10; i++){
// for(int j = i + 1; j <= 10; j++) adj[i].pb(j);
// }
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 = (1 + ans) % mod;
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
436 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
456 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
436 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
456 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
452 KB |
Output is correct |
26 |
Correct |
2 ms |
424 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
3 ms |
352 KB |
Output is correct |
29 |
Correct |
3 ms |
356 KB |
Output is correct |
30 |
Correct |
3 ms |
476 KB |
Output is correct |
31 |
Correct |
3 ms |
348 KB |
Output is correct |
32 |
Correct |
15 ms |
708 KB |
Output is correct |
33 |
Correct |
16 ms |
700 KB |
Output is correct |
34 |
Correct |
18 ms |
676 KB |
Output is correct |
35 |
Correct |
19 ms |
680 KB |
Output is correct |
36 |
Correct |
21 ms |
740 KB |
Output is correct |
37 |
Correct |
22 ms |
780 KB |
Output is correct |
38 |
Correct |
23 ms |
1000 KB |
Output is correct |
39 |
Correct |
150 ms |
2572 KB |
Output is correct |
40 |
Correct |
159 ms |
2528 KB |
Output is correct |
41 |
Correct |
168 ms |
2404 KB |
Output is correct |
42 |
Correct |
176 ms |
2648 KB |
Output is correct |
43 |
Correct |
188 ms |
2520 KB |
Output is correct |
44 |
Correct |
182 ms |
2528 KB |
Output is correct |
45 |
Correct |
195 ms |
2420 KB |
Output is correct |
46 |
Correct |
223 ms |
2512 KB |
Output is correct |
47 |
Correct |
227 ms |
2508 KB |
Output is correct |
48 |
Correct |
161 ms |
2544 KB |
Output is correct |
49 |
Correct |
172 ms |
2508 KB |
Output is correct |
50 |
Correct |
166 ms |
2508 KB |
Output is correct |
51 |
Correct |
163 ms |
2512 KB |
Output is correct |
52 |
Incorrect |
1667 ms |
17532 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
436 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
456 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
452 KB |
Output is correct |
26 |
Correct |
2 ms |
424 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
3 ms |
352 KB |
Output is correct |
29 |
Correct |
3 ms |
356 KB |
Output is correct |
30 |
Correct |
3 ms |
476 KB |
Output is correct |
31 |
Correct |
3 ms |
348 KB |
Output is correct |
32 |
Correct |
15 ms |
708 KB |
Output is correct |
33 |
Correct |
16 ms |
700 KB |
Output is correct |
34 |
Correct |
18 ms |
676 KB |
Output is correct |
35 |
Correct |
19 ms |
680 KB |
Output is correct |
36 |
Correct |
21 ms |
740 KB |
Output is correct |
37 |
Correct |
22 ms |
780 KB |
Output is correct |
38 |
Correct |
23 ms |
1000 KB |
Output is correct |
39 |
Correct |
150 ms |
2572 KB |
Output is correct |
40 |
Correct |
159 ms |
2528 KB |
Output is correct |
41 |
Correct |
168 ms |
2404 KB |
Output is correct |
42 |
Correct |
176 ms |
2648 KB |
Output is correct |
43 |
Correct |
188 ms |
2520 KB |
Output is correct |
44 |
Correct |
182 ms |
2528 KB |
Output is correct |
45 |
Correct |
195 ms |
2420 KB |
Output is correct |
46 |
Correct |
223 ms |
2512 KB |
Output is correct |
47 |
Correct |
227 ms |
2508 KB |
Output is correct |
48 |
Correct |
161 ms |
2544 KB |
Output is correct |
49 |
Correct |
172 ms |
2508 KB |
Output is correct |
50 |
Correct |
166 ms |
2508 KB |
Output is correct |
51 |
Correct |
163 ms |
2512 KB |
Output is correct |
52 |
Incorrect |
1667 ms |
17532 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
436 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
456 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
2 ms |
452 KB |
Output is correct |
26 |
Correct |
2 ms |
424 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
3 ms |
352 KB |
Output is correct |
29 |
Correct |
3 ms |
356 KB |
Output is correct |
30 |
Correct |
3 ms |
476 KB |
Output is correct |
31 |
Correct |
3 ms |
348 KB |
Output is correct |
32 |
Correct |
15 ms |
708 KB |
Output is correct |
33 |
Correct |
16 ms |
700 KB |
Output is correct |
34 |
Correct |
18 ms |
676 KB |
Output is correct |
35 |
Correct |
19 ms |
680 KB |
Output is correct |
36 |
Correct |
21 ms |
740 KB |
Output is correct |
37 |
Correct |
22 ms |
780 KB |
Output is correct |
38 |
Correct |
23 ms |
1000 KB |
Output is correct |
39 |
Correct |
150 ms |
2572 KB |
Output is correct |
40 |
Correct |
159 ms |
2528 KB |
Output is correct |
41 |
Correct |
168 ms |
2404 KB |
Output is correct |
42 |
Correct |
176 ms |
2648 KB |
Output is correct |
43 |
Correct |
188 ms |
2520 KB |
Output is correct |
44 |
Correct |
182 ms |
2528 KB |
Output is correct |
45 |
Correct |
195 ms |
2420 KB |
Output is correct |
46 |
Correct |
223 ms |
2512 KB |
Output is correct |
47 |
Correct |
227 ms |
2508 KB |
Output is correct |
48 |
Correct |
161 ms |
2544 KB |
Output is correct |
49 |
Correct |
172 ms |
2508 KB |
Output is correct |
50 |
Correct |
166 ms |
2508 KB |
Output is correct |
51 |
Correct |
163 ms |
2512 KB |
Output is correct |
52 |
Incorrect |
1667 ms |
17532 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |