Submission #237485

# Submission time Handle Problem Language Result Execution time Memory
237485 2020-06-07T02:02:06 Z _7_7_ Nice sequence (IZhO18_sequence) C++14
100 / 100
1389 ms 70792 KB
#include <bits/stdc++.h>                                           
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 4e5 + 11;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int T, n, m, timer, t[N], c[N];
bool cycle;
vi g[N];


void dfs (int v) {
	c[v] = 1;
	for (auto to : g[v]) {
		if (!c[to])  
			dfs(to);
		if (c[to] == 1)	 {
			cycle = 1;	
			return;
		}
	}
	t[v] = ++timer;
	c[v] = 2;
}

	
inline bool check (int k) {
    for (int i = 0; i <= k; ++i) 
    	g[i].clear();
    

	for (int i = 0; i <= k; ++i) {
		t[i] = 0; 
		c[i] = 0;
		if (i - n >= 0)
			g[i - n].pb(i);
		if (i - m >= 0)
			g[i].pb(i - m);
	}



	timer = 0;
	cycle = 0;

	for (int i = 0; i <= k && !cycle; ++i)
		if (!c[i])
			dfs(i);

	return cycle ^ 1;

}

main () {
	cin >> T;
	while (T--) {
		cin >> n >> m;
		int res = n + m - __gcd(n, m) - 1;
		check(res);
		printf("%d\n", res);
		for (int i = 1; i <= res; ++i)
			printf("%d ", t[i] - t[i - 1]);
		printf("\n");
	}
}

Compilation message

sequence.cpp: In function 'bool check(int)':
sequence.cpp:62:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
     for (int i = 0; i <= k; ++i) 
     ^~~
sequence.cpp:66:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  for (int i = 0; i <= k; ++i) {
  ^~~
sequence.cpp: At global scope:
sequence.cpp:88:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Ok
2 Correct 10 ms 9728 KB Ok
3 Correct 10 ms 9728 KB Ok
4 Correct 10 ms 9728 KB Ok
5 Correct 11 ms 9728 KB Ok
6 Correct 10 ms 9728 KB Ok
7 Correct 10 ms 9728 KB Ok
8 Correct 10 ms 9728 KB Ok
9 Correct 10 ms 9728 KB Ok
10 Correct 10 ms 9728 KB Ok
11 Correct 10 ms 9728 KB Ok
12 Correct 10 ms 9728 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Ok
2 Correct 10 ms 9728 KB Ok
3 Correct 10 ms 9728 KB Ok
4 Correct 10 ms 9728 KB Ok
5 Correct 10 ms 9728 KB Ok
6 Correct 12 ms 9856 KB Ok
7 Correct 20 ms 10624 KB Ok
8 Correct 15 ms 10112 KB Ok
9 Correct 23 ms 10752 KB Ok
10 Correct 17 ms 10368 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9728 KB Ok
2 Correct 10 ms 9728 KB Ok
3 Correct 10 ms 9728 KB Ok
4 Correct 10 ms 9728 KB Ok
5 Correct 10 ms 9728 KB Ok
6 Correct 10 ms 9728 KB Ok
7 Correct 10 ms 9728 KB Ok
8 Correct 10 ms 9728 KB Ok
9 Correct 10 ms 9728 KB Ok
10 Correct 13 ms 9728 KB Ok
11 Correct 10 ms 9728 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Ok
2 Correct 10 ms 9728 KB Ok
3 Correct 10 ms 9728 KB Ok
4 Correct 10 ms 9728 KB Ok
5 Correct 10 ms 9728 KB Ok
6 Correct 109 ms 22648 KB Ok
7 Correct 94 ms 28792 KB Ok
8 Correct 176 ms 31480 KB Ok
9 Correct 130 ms 28792 KB Ok
10 Correct 77 ms 19704 KB Ok
11 Correct 119 ms 25336 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Ok
2 Correct 10 ms 9728 KB Ok
3 Correct 10 ms 9728 KB Ok
4 Correct 10 ms 9728 KB Ok
5 Correct 11 ms 9728 KB Ok
6 Correct 10 ms 9728 KB Ok
7 Correct 10 ms 9728 KB Ok
8 Correct 10 ms 9728 KB Ok
9 Correct 10 ms 9728 KB Ok
10 Correct 10 ms 9728 KB Ok
11 Correct 10 ms 9728 KB Ok
12 Correct 10 ms 9728 KB Ok
13 Correct 11 ms 9728 KB Ok
14 Correct 10 ms 9728 KB Ok
15 Correct 10 ms 9728 KB Ok
16 Correct 10 ms 9728 KB Ok
17 Correct 10 ms 9728 KB Ok
18 Correct 10 ms 9728 KB Ok
19 Correct 10 ms 9728 KB Ok
20 Correct 10 ms 9728 KB Ok
21 Correct 10 ms 9728 KB Ok
22 Correct 13 ms 9728 KB Ok
23 Correct 10 ms 9728 KB Ok
24 Correct 13 ms 9856 KB Ok
25 Correct 12 ms 9856 KB Ok
26 Correct 12 ms 9856 KB Ok
27 Correct 12 ms 9856 KB Ok
28 Correct 12 ms 9856 KB Ok
29 Correct 12 ms 9856 KB Ok
30 Correct 11 ms 9856 KB Ok
31 Correct 13 ms 9856 KB Ok
32 Correct 12 ms 9888 KB Ok
33 Correct 12 ms 9856 KB Ok
34 Correct 14 ms 10112 KB Ok
35 Correct 14 ms 10240 KB Ok
36 Correct 15 ms 10240 KB Ok
37 Correct 14 ms 10128 KB Ok
38 Correct 14 ms 10112 KB Ok
39 Correct 14 ms 10112 KB Ok
40 Correct 14 ms 10112 KB Ok
41 Correct 14 ms 10112 KB Ok
42 Correct 14 ms 10112 KB Ok
43 Correct 14 ms 10240 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Ok
2 Correct 10 ms 9728 KB Ok
3 Correct 10 ms 9728 KB Ok
4 Correct 10 ms 9728 KB Ok
5 Correct 11 ms 9728 KB Ok
6 Correct 10 ms 9728 KB Ok
7 Correct 10 ms 9728 KB Ok
8 Correct 10 ms 9728 KB Ok
9 Correct 10 ms 9728 KB Ok
10 Correct 10 ms 9728 KB Ok
11 Correct 10 ms 9728 KB Ok
12 Correct 10 ms 9728 KB Ok
13 Correct 10 ms 9728 KB Ok
14 Correct 10 ms 9728 KB Ok
15 Correct 10 ms 9728 KB Ok
16 Correct 10 ms 9728 KB Ok
17 Correct 10 ms 9728 KB Ok
18 Correct 12 ms 9856 KB Ok
19 Correct 20 ms 10624 KB Ok
20 Correct 15 ms 10112 KB Ok
21 Correct 23 ms 10752 KB Ok
22 Correct 17 ms 10368 KB Ok
23 Correct 11 ms 9728 KB Ok
24 Correct 10 ms 9728 KB Ok
25 Correct 10 ms 9728 KB Ok
26 Correct 10 ms 9728 KB Ok
27 Correct 10 ms 9728 KB Ok
28 Correct 10 ms 9728 KB Ok
29 Correct 10 ms 9728 KB Ok
30 Correct 10 ms 9728 KB Ok
31 Correct 10 ms 9728 KB Ok
32 Correct 13 ms 9728 KB Ok
33 Correct 10 ms 9728 KB Ok
34 Correct 13 ms 9856 KB Ok
35 Correct 12 ms 9856 KB Ok
36 Correct 12 ms 9856 KB Ok
37 Correct 12 ms 9856 KB Ok
38 Correct 12 ms 9856 KB Ok
39 Correct 12 ms 9856 KB Ok
40 Correct 11 ms 9856 KB Ok
41 Correct 13 ms 9856 KB Ok
42 Correct 12 ms 9888 KB Ok
43 Correct 12 ms 9856 KB Ok
44 Correct 14 ms 10112 KB Ok
45 Correct 14 ms 10240 KB Ok
46 Correct 15 ms 10240 KB Ok
47 Correct 14 ms 10128 KB Ok
48 Correct 14 ms 10112 KB Ok
49 Correct 14 ms 10112 KB Ok
50 Correct 14 ms 10112 KB Ok
51 Correct 14 ms 10112 KB Ok
52 Correct 14 ms 10112 KB Ok
53 Correct 14 ms 10240 KB Ok
54 Correct 82 ms 14968 KB Ok
55 Correct 94 ms 15352 KB Ok
56 Correct 97 ms 15608 KB Ok
57 Correct 70 ms 14328 KB Ok
58 Correct 84 ms 14712 KB Ok
59 Correct 79 ms 14456 KB Ok
60 Correct 70 ms 14072 KB Ok
61 Correct 73 ms 14584 KB Ok
62 Correct 96 ms 15096 KB Ok
63 Correct 75 ms 14456 KB Ok
64 Correct 90 ms 15224 KB Ok
65 Correct 85 ms 15096 KB Ok
66 Correct 82 ms 14840 KB Ok
67 Correct 72 ms 14584 KB Ok
68 Correct 84 ms 14800 KB Ok
69 Correct 210 ms 24056 KB Ok
70 Correct 241 ms 24736 KB Ok
71 Correct 234 ms 24056 KB Ok
72 Correct 237 ms 24312 KB Ok
73 Correct 230 ms 23416 KB Ok
74 Correct 212 ms 23160 KB Ok
75 Correct 198 ms 23544 KB Ok
76 Correct 221 ms 24312 KB Ok
77 Correct 228 ms 22776 KB Ok
78 Correct 210 ms 23160 KB Ok
79 Correct 205 ms 23928 KB Ok
80 Correct 221 ms 24184 KB Ok
81 Correct 249 ms 23416 KB Ok
82 Correct 255 ms 23800 KB Ok
83 Correct 228 ms 23392 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Ok
2 Correct 10 ms 9728 KB Ok
3 Correct 10 ms 9728 KB Ok
4 Correct 10 ms 9728 KB Ok
5 Correct 11 ms 9728 KB Ok
6 Correct 10 ms 9728 KB Ok
7 Correct 10 ms 9728 KB Ok
8 Correct 10 ms 9728 KB Ok
9 Correct 10 ms 9728 KB Ok
10 Correct 10 ms 9728 KB Ok
11 Correct 10 ms 9728 KB Ok
12 Correct 10 ms 9728 KB Ok
13 Correct 10 ms 9728 KB Ok
14 Correct 10 ms 9728 KB Ok
15 Correct 10 ms 9728 KB Ok
16 Correct 10 ms 9728 KB Ok
17 Correct 10 ms 9728 KB Ok
18 Correct 12 ms 9856 KB Ok
19 Correct 20 ms 10624 KB Ok
20 Correct 15 ms 10112 KB Ok
21 Correct 23 ms 10752 KB Ok
22 Correct 17 ms 10368 KB Ok
23 Correct 11 ms 9728 KB Ok
24 Correct 10 ms 9728 KB Ok
25 Correct 10 ms 9728 KB Ok
26 Correct 10 ms 9728 KB Ok
27 Correct 10 ms 9728 KB Ok
28 Correct 10 ms 9728 KB Ok
29 Correct 10 ms 9728 KB Ok
30 Correct 10 ms 9728 KB Ok
31 Correct 10 ms 9728 KB Ok
32 Correct 13 ms 9728 KB Ok
33 Correct 10 ms 9728 KB Ok
34 Correct 10 ms 9728 KB Ok
35 Correct 10 ms 9728 KB Ok
36 Correct 10 ms 9728 KB Ok
37 Correct 10 ms 9728 KB Ok
38 Correct 10 ms 9728 KB Ok
39 Correct 109 ms 22648 KB Ok
40 Correct 94 ms 28792 KB Ok
41 Correct 176 ms 31480 KB Ok
42 Correct 130 ms 28792 KB Ok
43 Correct 77 ms 19704 KB Ok
44 Correct 119 ms 25336 KB Ok
45 Correct 13 ms 9856 KB Ok
46 Correct 12 ms 9856 KB Ok
47 Correct 12 ms 9856 KB Ok
48 Correct 12 ms 9856 KB Ok
49 Correct 12 ms 9856 KB Ok
50 Correct 12 ms 9856 KB Ok
51 Correct 11 ms 9856 KB Ok
52 Correct 13 ms 9856 KB Ok
53 Correct 12 ms 9888 KB Ok
54 Correct 12 ms 9856 KB Ok
55 Correct 14 ms 10112 KB Ok
56 Correct 14 ms 10240 KB Ok
57 Correct 15 ms 10240 KB Ok
58 Correct 14 ms 10128 KB Ok
59 Correct 14 ms 10112 KB Ok
60 Correct 14 ms 10112 KB Ok
61 Correct 14 ms 10112 KB Ok
62 Correct 14 ms 10112 KB Ok
63 Correct 14 ms 10112 KB Ok
64 Correct 14 ms 10240 KB Ok
65 Correct 82 ms 14968 KB Ok
66 Correct 94 ms 15352 KB Ok
67 Correct 97 ms 15608 KB Ok
68 Correct 70 ms 14328 KB Ok
69 Correct 84 ms 14712 KB Ok
70 Correct 79 ms 14456 KB Ok
71 Correct 70 ms 14072 KB Ok
72 Correct 73 ms 14584 KB Ok
73 Correct 96 ms 15096 KB Ok
74 Correct 75 ms 14456 KB Ok
75 Correct 90 ms 15224 KB Ok
76 Correct 85 ms 15096 KB Ok
77 Correct 82 ms 14840 KB Ok
78 Correct 72 ms 14584 KB Ok
79 Correct 84 ms 14800 KB Ok
80 Correct 210 ms 24056 KB Ok
81 Correct 241 ms 24736 KB Ok
82 Correct 234 ms 24056 KB Ok
83 Correct 237 ms 24312 KB Ok
84 Correct 230 ms 23416 KB Ok
85 Correct 212 ms 23160 KB Ok
86 Correct 198 ms 23544 KB Ok
87 Correct 221 ms 24312 KB Ok
88 Correct 228 ms 22776 KB Ok
89 Correct 210 ms 23160 KB Ok
90 Correct 205 ms 23928 KB Ok
91 Correct 221 ms 24184 KB Ok
92 Correct 249 ms 23416 KB Ok
93 Correct 255 ms 23800 KB Ok
94 Correct 228 ms 23392 KB Ok
95 Correct 207 ms 23416 KB Ok
96 Correct 286 ms 29304 KB Ok
97 Correct 262 ms 25976 KB Ok
98 Correct 197 ms 25976 KB Ok
99 Correct 234 ms 25336 KB Ok
100 Correct 250 ms 24952 KB Ok
101 Correct 244 ms 27768 KB Ok
102 Correct 237 ms 26104 KB Ok
103 Correct 235 ms 26876 KB Ok
104 Correct 280 ms 28664 KB Ok
105 Correct 277 ms 28924 KB Ok
106 Correct 245 ms 29176 KB Ok
107 Correct 262 ms 28152 KB Ok
108 Correct 313 ms 29176 KB Ok
109 Correct 283 ms 30072 KB Ok
110 Correct 1070 ms 67960 KB Ok
111 Correct 1188 ms 70136 KB Ok
112 Correct 1172 ms 66040 KB Ok
113 Correct 1389 ms 70792 KB Ok
114 Correct 1140 ms 70268 KB Ok
115 Correct 1188 ms 67576 KB Ok
116 Correct 1179 ms 70068 KB Ok
117 Correct 1119 ms 69604 KB Ok
118 Correct 1239 ms 70136 KB Ok
119 Correct 1172 ms 68856 KB Ok
120 Correct 1153 ms 68760 KB Ok
121 Correct 1271 ms 68784 KB Ok
122 Correct 1128 ms 68472 KB Ok
123 Correct 1386 ms 70264 KB Ok
124 Correct 1087 ms 64120 KB Ok
125 Correct 453 ms 54356 KB Ok