# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
389772 | 2021-04-14T14:01:33 Z | BartolM | Nice sequence (IZhO18_sequence) | C++17 | 2000 ms | 39200 KB |
#define DEBUG 1 #include <bits/stdc++.h> using namespace std; #define X first #define Y second #define mp make_pair #define pb push_back typedef long long ll; typedef pair <int, int> pii; typedef pair <int, pii> pip; typedef pair <pii, int> ppi; typedef pair <ll, ll> pll; const int INF=0x3f3f3f3f; const int N=4e5+5; int n, m; vector <int> ls[N]; //(i->j) i veci od j int in[N], bio[N], sol[N]; queue <int> Q; void reset(int x) { for (int i=0; i<=x; ++i) ls[i].clear(), in[i]=0, bio[i]=0; } void build(int x) { for (int i=1; i<=x; ++i) { if (i-n>=0) ls[i-n].pb(i), in[i]++; if (i-m>=0) ls[i].pb(i-m), in[i-m]++; } } int dfs(int node) { if (bio[node]==2) return 0; if (bio[node]==1) return 1; bio[node]=1; int ret=0; for (int sus:ls[node]) ret|=dfs(sus); bio[node]=2; return ret; } void topo_sort(int gr) { for (int i=0; i<=gr; ++i) if (!in[i]) Q.push(i); int curr=gr+1; while (!Q.empty()) { int node=Q.front(); Q.pop(); sol[node]=curr--; for (int sus:ls[node]) { in[sus]--; if (!in[sus]) Q.push(sus); } } } void solve() { int lo=0, hi=2*max(n, m), mid; while (lo<hi) { mid=(lo+hi+1)/2; build(mid); int fl=0; for (int i=0; i<=mid; ++i) fl+=dfs(i); if (fl) hi=mid-1; else lo=mid; reset(mid); } build(lo); topo_sort(lo); printf("%d\n", lo); for (int i=1; i<=lo; ++i) printf("%d ", sol[i]-sol[i-1]); printf("\n"); reset(lo); } void load() { scanf("%d %d", &n, &m); } int main() { int t; scanf("%d", &t); while (t--) { load(); solve(); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9676 KB | Ok |
2 | Correct | 6 ms | 9676 KB | Ok |
3 | Correct | 6 ms | 9676 KB | Ok |
4 | Correct | 6 ms | 9676 KB | Ok |
5 | Correct | 6 ms | 9676 KB | Ok |
6 | Correct | 6 ms | 9676 KB | Ok |
7 | Correct | 6 ms | 9676 KB | Ok |
8 | Correct | 6 ms | 9676 KB | Ok |
9 | Correct | 6 ms | 9676 KB | Ok |
10 | Correct | 6 ms | 9676 KB | Ok |
11 | Correct | 6 ms | 9696 KB | Ok |
12 | Correct | 6 ms | 9676 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9676 KB | Ok |
2 | Correct | 6 ms | 9676 KB | Ok |
3 | Correct | 6 ms | 9696 KB | Ok |
4 | Correct | 6 ms | 9676 KB | Ok |
5 | Correct | 7 ms | 9716 KB | Ok |
6 | Correct | 12 ms | 9932 KB | Ok |
7 | Correct | 41 ms | 11064 KB | Ok |
8 | Correct | 21 ms | 10316 KB | Ok |
9 | Correct | 47 ms | 11256 KB | Ok |
10 | Correct | 29 ms | 10564 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 9696 KB | Ok |
2 | Correct | 6 ms | 9676 KB | Ok |
3 | Correct | 6 ms | 9676 KB | Ok |
4 | Correct | 8 ms | 9676 KB | Ok |
5 | Correct | 6 ms | 9692 KB | Ok |
6 | Correct | 6 ms | 9676 KB | Ok |
7 | Correct | 6 ms | 9676 KB | Ok |
8 | Correct | 6 ms | 9676 KB | Ok |
9 | Correct | 6 ms | 9676 KB | Ok |
10 | Correct | 6 ms | 9696 KB | Ok |
11 | Correct | 6 ms | 9676 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9676 KB | Ok |
2 | Correct | 6 ms | 9696 KB | Ok |
3 | Correct | 6 ms | 9676 KB | Ok |
4 | Correct | 6 ms | 9676 KB | Ok |
5 | Correct | 6 ms | 9676 KB | Ok |
6 | Correct | 414 ms | 26700 KB | Ok |
7 | Correct | 366 ms | 29564 KB | Ok |
8 | Correct | 819 ms | 31144 KB | Ok |
9 | Correct | 493 ms | 29640 KB | Ok |
10 | Correct | 263 ms | 20804 KB | Ok |
11 | Correct | 429 ms | 31020 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9676 KB | Ok |
2 | Correct | 6 ms | 9676 KB | Ok |
3 | Correct | 6 ms | 9676 KB | Ok |
4 | Correct | 6 ms | 9676 KB | Ok |
5 | Correct | 6 ms | 9676 KB | Ok |
6 | Correct | 6 ms | 9676 KB | Ok |
7 | Correct | 6 ms | 9676 KB | Ok |
8 | Correct | 6 ms | 9676 KB | Ok |
9 | Correct | 6 ms | 9676 KB | Ok |
10 | Correct | 6 ms | 9676 KB | Ok |
11 | Correct | 6 ms | 9696 KB | Ok |
12 | Correct | 6 ms | 9676 KB | Ok |
13 | Correct | 7 ms | 9696 KB | Ok |
14 | Correct | 6 ms | 9676 KB | Ok |
15 | Correct | 6 ms | 9676 KB | Ok |
16 | Correct | 8 ms | 9676 KB | Ok |
17 | Correct | 6 ms | 9692 KB | Ok |
18 | Correct | 6 ms | 9676 KB | Ok |
19 | Correct | 6 ms | 9676 KB | Ok |
20 | Correct | 6 ms | 9676 KB | Ok |
21 | Correct | 6 ms | 9676 KB | Ok |
22 | Correct | 6 ms | 9696 KB | Ok |
23 | Correct | 6 ms | 9676 KB | Ok |
24 | Correct | 11 ms | 9888 KB | Ok |
25 | Correct | 11 ms | 9804 KB | Ok |
26 | Correct | 11 ms | 9900 KB | Ok |
27 | Correct | 11 ms | 9820 KB | Ok |
28 | Correct | 10 ms | 9804 KB | Ok |
29 | Correct | 10 ms | 9872 KB | Ok |
30 | Correct | 10 ms | 9804 KB | Ok |
31 | Correct | 11 ms | 9804 KB | Ok |
32 | Correct | 11 ms | 9804 KB | Ok |
33 | Correct | 11 ms | 9824 KB | Ok |
34 | Correct | 20 ms | 10160 KB | Ok |
35 | Correct | 19 ms | 10188 KB | Ok |
36 | Correct | 19 ms | 10188 KB | Ok |
37 | Correct | 20 ms | 10188 KB | Ok |
38 | Correct | 19 ms | 10188 KB | Ok |
39 | Correct | 19 ms | 10060 KB | Ok |
40 | Correct | 24 ms | 10136 KB | Ok |
41 | Correct | 20 ms | 10136 KB | Ok |
42 | Correct | 20 ms | 10140 KB | Ok |
43 | Correct | 20 ms | 10188 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9676 KB | Ok |
2 | Correct | 6 ms | 9676 KB | Ok |
3 | Correct | 6 ms | 9676 KB | Ok |
4 | Correct | 6 ms | 9676 KB | Ok |
5 | Correct | 6 ms | 9676 KB | Ok |
6 | Correct | 6 ms | 9676 KB | Ok |
7 | Correct | 6 ms | 9676 KB | Ok |
8 | Correct | 6 ms | 9676 KB | Ok |
9 | Correct | 6 ms | 9676 KB | Ok |
10 | Correct | 6 ms | 9676 KB | Ok |
11 | Correct | 6 ms | 9696 KB | Ok |
12 | Correct | 6 ms | 9676 KB | Ok |
13 | Correct | 6 ms | 9676 KB | Ok |
14 | Correct | 6 ms | 9676 KB | Ok |
15 | Correct | 6 ms | 9696 KB | Ok |
16 | Correct | 6 ms | 9676 KB | Ok |
17 | Correct | 7 ms | 9716 KB | Ok |
18 | Correct | 12 ms | 9932 KB | Ok |
19 | Correct | 41 ms | 11064 KB | Ok |
20 | Correct | 21 ms | 10316 KB | Ok |
21 | Correct | 47 ms | 11256 KB | Ok |
22 | Correct | 29 ms | 10564 KB | Ok |
23 | Correct | 7 ms | 9696 KB | Ok |
24 | Correct | 6 ms | 9676 KB | Ok |
25 | Correct | 6 ms | 9676 KB | Ok |
26 | Correct | 8 ms | 9676 KB | Ok |
27 | Correct | 6 ms | 9692 KB | Ok |
28 | Correct | 6 ms | 9676 KB | Ok |
29 | Correct | 6 ms | 9676 KB | Ok |
30 | Correct | 6 ms | 9676 KB | Ok |
31 | Correct | 6 ms | 9676 KB | Ok |
32 | Correct | 6 ms | 9696 KB | Ok |
33 | Correct | 6 ms | 9676 KB | Ok |
34 | Correct | 11 ms | 9888 KB | Ok |
35 | Correct | 11 ms | 9804 KB | Ok |
36 | Correct | 11 ms | 9900 KB | Ok |
37 | Correct | 11 ms | 9820 KB | Ok |
38 | Correct | 10 ms | 9804 KB | Ok |
39 | Correct | 10 ms | 9872 KB | Ok |
40 | Correct | 10 ms | 9804 KB | Ok |
41 | Correct | 11 ms | 9804 KB | Ok |
42 | Correct | 11 ms | 9804 KB | Ok |
43 | Correct | 11 ms | 9824 KB | Ok |
44 | Correct | 20 ms | 10160 KB | Ok |
45 | Correct | 19 ms | 10188 KB | Ok |
46 | Correct | 19 ms | 10188 KB | Ok |
47 | Correct | 20 ms | 10188 KB | Ok |
48 | Correct | 19 ms | 10188 KB | Ok |
49 | Correct | 19 ms | 10060 KB | Ok |
50 | Correct | 24 ms | 10136 KB | Ok |
51 | Correct | 20 ms | 10136 KB | Ok |
52 | Correct | 20 ms | 10140 KB | Ok |
53 | Correct | 20 ms | 10188 KB | Ok |
54 | Correct | 302 ms | 15800 KB | Ok |
55 | Correct | 381 ms | 15968 KB | Ok |
56 | Correct | 360 ms | 16216 KB | Ok |
57 | Correct | 221 ms | 15292 KB | Ok |
58 | Correct | 285 ms | 15904 KB | Ok |
59 | Correct | 255 ms | 15844 KB | Ok |
60 | Correct | 214 ms | 15300 KB | Ok |
61 | Correct | 241 ms | 15592 KB | Ok |
62 | Correct | 326 ms | 16068 KB | Ok |
63 | Correct | 252 ms | 15428 KB | Ok |
64 | Correct | 340 ms | 15920 KB | Ok |
65 | Correct | 290 ms | 15876 KB | Ok |
66 | Correct | 264 ms | 15556 KB | Ok |
67 | Correct | 230 ms | 15300 KB | Ok |
68 | Correct | 269 ms | 15940 KB | Ok |
69 | Correct | 1014 ms | 24128 KB | Ok |
70 | Correct | 1049 ms | 25256 KB | Ok |
71 | Correct | 1122 ms | 23576 KB | Ok |
72 | Correct | 1080 ms | 24452 KB | Ok |
73 | Correct | 899 ms | 24124 KB | Ok |
74 | Correct | 1061 ms | 23400 KB | Ok |
75 | Correct | 1061 ms | 23244 KB | Ok |
76 | Correct | 968 ms | 24952 KB | Ok |
77 | Correct | 957 ms | 23008 KB | Ok |
78 | Correct | 907 ms | 24644 KB | Ok |
79 | Correct | 934 ms | 24292 KB | Ok |
80 | Correct | 966 ms | 24004 KB | Ok |
81 | Correct | 1301 ms | 24672 KB | Ok |
82 | Correct | 1049 ms | 24308 KB | Ok |
83 | Correct | 1033 ms | 23364 KB | Ok |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9676 KB | Ok |
2 | Correct | 6 ms | 9676 KB | Ok |
3 | Correct | 6 ms | 9676 KB | Ok |
4 | Correct | 6 ms | 9676 KB | Ok |
5 | Correct | 6 ms | 9676 KB | Ok |
6 | Correct | 6 ms | 9676 KB | Ok |
7 | Correct | 6 ms | 9676 KB | Ok |
8 | Correct | 6 ms | 9676 KB | Ok |
9 | Correct | 6 ms | 9676 KB | Ok |
10 | Correct | 6 ms | 9676 KB | Ok |
11 | Correct | 6 ms | 9696 KB | Ok |
12 | Correct | 6 ms | 9676 KB | Ok |
13 | Correct | 6 ms | 9676 KB | Ok |
14 | Correct | 6 ms | 9676 KB | Ok |
15 | Correct | 6 ms | 9696 KB | Ok |
16 | Correct | 6 ms | 9676 KB | Ok |
17 | Correct | 7 ms | 9716 KB | Ok |
18 | Correct | 12 ms | 9932 KB | Ok |
19 | Correct | 41 ms | 11064 KB | Ok |
20 | Correct | 21 ms | 10316 KB | Ok |
21 | Correct | 47 ms | 11256 KB | Ok |
22 | Correct | 29 ms | 10564 KB | Ok |
23 | Correct | 7 ms | 9696 KB | Ok |
24 | Correct | 6 ms | 9676 KB | Ok |
25 | Correct | 6 ms | 9676 KB | Ok |
26 | Correct | 8 ms | 9676 KB | Ok |
27 | Correct | 6 ms | 9692 KB | Ok |
28 | Correct | 6 ms | 9676 KB | Ok |
29 | Correct | 6 ms | 9676 KB | Ok |
30 | Correct | 6 ms | 9676 KB | Ok |
31 | Correct | 6 ms | 9676 KB | Ok |
32 | Correct | 6 ms | 9696 KB | Ok |
33 | Correct | 6 ms | 9676 KB | Ok |
34 | Correct | 6 ms | 9676 KB | Ok |
35 | Correct | 6 ms | 9696 KB | Ok |
36 | Correct | 6 ms | 9676 KB | Ok |
37 | Correct | 6 ms | 9676 KB | Ok |
38 | Correct | 6 ms | 9676 KB | Ok |
39 | Correct | 414 ms | 26700 KB | Ok |
40 | Correct | 366 ms | 29564 KB | Ok |
41 | Correct | 819 ms | 31144 KB | Ok |
42 | Correct | 493 ms | 29640 KB | Ok |
43 | Correct | 263 ms | 20804 KB | Ok |
44 | Correct | 429 ms | 31020 KB | Ok |
45 | Correct | 11 ms | 9888 KB | Ok |
46 | Correct | 11 ms | 9804 KB | Ok |
47 | Correct | 11 ms | 9900 KB | Ok |
48 | Correct | 11 ms | 9820 KB | Ok |
49 | Correct | 10 ms | 9804 KB | Ok |
50 | Correct | 10 ms | 9872 KB | Ok |
51 | Correct | 10 ms | 9804 KB | Ok |
52 | Correct | 11 ms | 9804 KB | Ok |
53 | Correct | 11 ms | 9804 KB | Ok |
54 | Correct | 11 ms | 9824 KB | Ok |
55 | Correct | 20 ms | 10160 KB | Ok |
56 | Correct | 19 ms | 10188 KB | Ok |
57 | Correct | 19 ms | 10188 KB | Ok |
58 | Correct | 20 ms | 10188 KB | Ok |
59 | Correct | 19 ms | 10188 KB | Ok |
60 | Correct | 19 ms | 10060 KB | Ok |
61 | Correct | 24 ms | 10136 KB | Ok |
62 | Correct | 20 ms | 10136 KB | Ok |
63 | Correct | 20 ms | 10140 KB | Ok |
64 | Correct | 20 ms | 10188 KB | Ok |
65 | Correct | 302 ms | 15800 KB | Ok |
66 | Correct | 381 ms | 15968 KB | Ok |
67 | Correct | 360 ms | 16216 KB | Ok |
68 | Correct | 221 ms | 15292 KB | Ok |
69 | Correct | 285 ms | 15904 KB | Ok |
70 | Correct | 255 ms | 15844 KB | Ok |
71 | Correct | 214 ms | 15300 KB | Ok |
72 | Correct | 241 ms | 15592 KB | Ok |
73 | Correct | 326 ms | 16068 KB | Ok |
74 | Correct | 252 ms | 15428 KB | Ok |
75 | Correct | 340 ms | 15920 KB | Ok |
76 | Correct | 290 ms | 15876 KB | Ok |
77 | Correct | 264 ms | 15556 KB | Ok |
78 | Correct | 230 ms | 15300 KB | Ok |
79 | Correct | 269 ms | 15940 KB | Ok |
80 | Correct | 1014 ms | 24128 KB | Ok |
81 | Correct | 1049 ms | 25256 KB | Ok |
82 | Correct | 1122 ms | 23576 KB | Ok |
83 | Correct | 1080 ms | 24452 KB | Ok |
84 | Correct | 899 ms | 24124 KB | Ok |
85 | Correct | 1061 ms | 23400 KB | Ok |
86 | Correct | 1061 ms | 23244 KB | Ok |
87 | Correct | 968 ms | 24952 KB | Ok |
88 | Correct | 957 ms | 23008 KB | Ok |
89 | Correct | 907 ms | 24644 KB | Ok |
90 | Correct | 934 ms | 24292 KB | Ok |
91 | Correct | 966 ms | 24004 KB | Ok |
92 | Correct | 1301 ms | 24672 KB | Ok |
93 | Correct | 1049 ms | 24308 KB | Ok |
94 | Correct | 1033 ms | 23364 KB | Ok |
95 | Correct | 918 ms | 26448 KB | Ok |
96 | Correct | 1354 ms | 33732 KB | Ok |
97 | Correct | 1162 ms | 30172 KB | Ok |
98 | Correct | 742 ms | 30444 KB | Ok |
99 | Correct | 1020 ms | 28736 KB | Ok |
100 | Correct | 1061 ms | 29396 KB | Ok |
101 | Correct | 1036 ms | 31472 KB | Ok |
102 | Correct | 1082 ms | 29548 KB | Ok |
103 | Correct | 1037 ms | 31520 KB | Ok |
104 | Correct | 1350 ms | 32980 KB | Ok |
105 | Correct | 1300 ms | 32540 KB | Ok |
106 | Correct | 1174 ms | 32128 KB | Ok |
107 | Correct | 1076 ms | 31592 KB | Ok |
108 | Correct | 1641 ms | 32848 KB | Ok |
109 | Correct | 1528 ms | 33880 KB | Ok |
110 | Execution timed out | 2098 ms | 39200 KB | Time limit exceeded |
111 | Halted | 0 ms | 0 KB | - |