#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>
using namespace std;
#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer {cout << "NO"; exit(0);}
#define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k)
const long long mxn = 4e5 + 110;
const long long mnn = 1e3 + 2;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
const long long OO = 1e8;
typedef long long llong;
typedef unsigned long long ullong;
int n, m;
int pr[mxn], a[mxn];
int used[mxn];
vector<int> g[mxn], top;
bool dfs(int x){
used[x] = 1;
bool ok = true;
for(auto to : g[x]){
if(used[to] == 0) ok = (ok & dfs(to));
else if(used[to] == 1) {
ok = false;
}
if (!ok) return false;
}
used[x] = 2;
return ok;
}
bool check(int k){
for(int i = 1; i <= k; i++){
used[i] = 0;
g[i].clear();
}
for(int i = 1; i + min(n, m) <= k; i++){
if(i + n <= k)
g[i].push_back(i + n);
if(i + m <= k)
g[i + m].push_back(i);
}
return dfs(1);
}
void dfss(int x){
used[x] = 1;
for(auto to : g[x]){
if(used[to] == 0){
dfss(to);
}
}
top.push_back(x);
}
void solve(){
cin >> n >> m;
if(n == m){
cout << n - 1 << nl;
for(int i = 1; i < n; i++){
cout << 1 << ' ';
}
cout << nl;
return ;
}
if(n == 1 || m % n == 0){
cout << m - 1 << nl;
for(int i = 1; i <= m - 1; i++) cout << -1 << ' ';
cout << nl;
return ;
}
if(m == 1 || n % m == 0){
cout << n - 1 << nl;
for(int i = 1; i <= n - 1; i++) cout << 1 << ' ';
cout << nl;
return ;
}
int l = 0, r = n + m + 1;
while(r - l > 1){
int m = (l + r) / 2;
if(check(m)){
l = m;
}else{
r = m - 1;
}
}
int ans = -1;
if(check(r)) ans = r;
else ans = l;
for(int i = 1; i <= ans; i++){
used[i] = 0;
}
top.clear();
cout << ans - 1 << nl;
for(int i = 1; i <= ans; i++){
if(used[i] == 0){
dfss(i);
}
}
reverse(top.begin(), top.end());
for(int i = 0; i < top.size(); i++){
pr[top[i]] = OO - i;
}
for(int i = 2; i <= ans; i++){
pr[i] -= pr[1];
}
pr[1] = 0;
for(int i = 2; i <= ans; i++){
a[i] = pr[i] - pr[i - 1];
}
for(int i = 2; i <= ans; i++){
cout << a[i] << ' ';
}
cout << nl;
}
int main() {
ios;
int t;
cin >> t;
while(t--){
solve();
}
}
Compilation message
sequence.cpp: In function 'void solve()':
sequence.cpp:135:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | for(int i = 0; i < top.size(); i++){
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Ok |
2 |
Correct |
7 ms |
9708 KB |
Ok |
3 |
Correct |
7 ms |
9708 KB |
Ok |
4 |
Correct |
7 ms |
9708 KB |
Ok |
5 |
Correct |
7 ms |
9708 KB |
Ok |
6 |
Correct |
7 ms |
9708 KB |
Ok |
7 |
Correct |
7 ms |
9708 KB |
Ok |
8 |
Correct |
7 ms |
9708 KB |
Ok |
9 |
Correct |
7 ms |
9708 KB |
Ok |
10 |
Correct |
7 ms |
9708 KB |
Ok |
11 |
Correct |
7 ms |
9708 KB |
Ok |
12 |
Correct |
7 ms |
9708 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Ok |
2 |
Correct |
7 ms |
9708 KB |
Ok |
3 |
Correct |
7 ms |
9708 KB |
Ok |
4 |
Correct |
7 ms |
9708 KB |
Ok |
5 |
Correct |
7 ms |
9708 KB |
Ok |
6 |
Correct |
10 ms |
9964 KB |
Ok |
7 |
Correct |
22 ms |
10988 KB |
Ok |
8 |
Correct |
14 ms |
10348 KB |
Ok |
9 |
Correct |
25 ms |
11116 KB |
Ok |
10 |
Correct |
17 ms |
10604 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Ok |
2 |
Correct |
7 ms |
9708 KB |
Ok |
3 |
Correct |
7 ms |
9708 KB |
Ok |
4 |
Correct |
7 ms |
9708 KB |
Ok |
5 |
Correct |
7 ms |
9728 KB |
Ok |
6 |
Correct |
7 ms |
9708 KB |
Ok |
7 |
Correct |
7 ms |
9708 KB |
Ok |
8 |
Correct |
7 ms |
9708 KB |
Ok |
9 |
Correct |
7 ms |
9708 KB |
Ok |
10 |
Correct |
7 ms |
9708 KB |
Ok |
11 |
Correct |
7 ms |
9708 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Ok |
2 |
Correct |
7 ms |
9708 KB |
Ok |
3 |
Correct |
7 ms |
9708 KB |
Ok |
4 |
Correct |
7 ms |
9708 KB |
Ok |
5 |
Correct |
7 ms |
9708 KB |
Ok |
6 |
Correct |
289 ms |
28256 KB |
Ok |
7 |
Correct |
305 ms |
30524 KB |
Ok |
8 |
Correct |
603 ms |
33248 KB |
Ok |
9 |
Correct |
378 ms |
30304 KB |
Ok |
10 |
Correct |
179 ms |
21348 KB |
Ok |
11 |
Correct |
309 ms |
31840 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Ok |
2 |
Correct |
7 ms |
9708 KB |
Ok |
3 |
Correct |
7 ms |
9708 KB |
Ok |
4 |
Correct |
7 ms |
9708 KB |
Ok |
5 |
Correct |
7 ms |
9708 KB |
Ok |
6 |
Correct |
7 ms |
9708 KB |
Ok |
7 |
Correct |
7 ms |
9708 KB |
Ok |
8 |
Correct |
7 ms |
9708 KB |
Ok |
9 |
Correct |
7 ms |
9708 KB |
Ok |
10 |
Correct |
7 ms |
9708 KB |
Ok |
11 |
Correct |
7 ms |
9708 KB |
Ok |
12 |
Correct |
7 ms |
9708 KB |
Ok |
13 |
Correct |
7 ms |
9708 KB |
Ok |
14 |
Correct |
7 ms |
9708 KB |
Ok |
15 |
Correct |
7 ms |
9708 KB |
Ok |
16 |
Correct |
7 ms |
9708 KB |
Ok |
17 |
Correct |
7 ms |
9728 KB |
Ok |
18 |
Correct |
7 ms |
9708 KB |
Ok |
19 |
Correct |
7 ms |
9708 KB |
Ok |
20 |
Correct |
7 ms |
9708 KB |
Ok |
21 |
Correct |
7 ms |
9708 KB |
Ok |
22 |
Correct |
7 ms |
9708 KB |
Ok |
23 |
Correct |
7 ms |
9708 KB |
Ok |
24 |
Correct |
11 ms |
9964 KB |
Ok |
25 |
Correct |
9 ms |
9964 KB |
Ok |
26 |
Correct |
9 ms |
9964 KB |
Ok |
27 |
Correct |
9 ms |
9964 KB |
Ok |
28 |
Correct |
9 ms |
9964 KB |
Ok |
29 |
Correct |
9 ms |
9964 KB |
Ok |
30 |
Correct |
9 ms |
9836 KB |
Ok |
31 |
Correct |
10 ms |
9964 KB |
Ok |
32 |
Correct |
9 ms |
9964 KB |
Ok |
33 |
Correct |
9 ms |
9964 KB |
Ok |
34 |
Correct |
14 ms |
10220 KB |
Ok |
35 |
Correct |
15 ms |
10220 KB |
Ok |
36 |
Correct |
15 ms |
10348 KB |
Ok |
37 |
Correct |
15 ms |
10220 KB |
Ok |
38 |
Correct |
15 ms |
10220 KB |
Ok |
39 |
Correct |
14 ms |
10220 KB |
Ok |
40 |
Correct |
15 ms |
10220 KB |
Ok |
41 |
Correct |
15 ms |
10220 KB |
Ok |
42 |
Correct |
15 ms |
10348 KB |
Ok |
43 |
Correct |
15 ms |
10220 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Ok |
2 |
Correct |
7 ms |
9708 KB |
Ok |
3 |
Correct |
7 ms |
9708 KB |
Ok |
4 |
Correct |
7 ms |
9708 KB |
Ok |
5 |
Correct |
7 ms |
9708 KB |
Ok |
6 |
Correct |
7 ms |
9708 KB |
Ok |
7 |
Correct |
7 ms |
9708 KB |
Ok |
8 |
Correct |
7 ms |
9708 KB |
Ok |
9 |
Correct |
7 ms |
9708 KB |
Ok |
10 |
Correct |
7 ms |
9708 KB |
Ok |
11 |
Correct |
7 ms |
9708 KB |
Ok |
12 |
Correct |
7 ms |
9708 KB |
Ok |
13 |
Correct |
7 ms |
9708 KB |
Ok |
14 |
Correct |
7 ms |
9708 KB |
Ok |
15 |
Correct |
7 ms |
9708 KB |
Ok |
16 |
Correct |
7 ms |
9708 KB |
Ok |
17 |
Correct |
7 ms |
9708 KB |
Ok |
18 |
Correct |
10 ms |
9964 KB |
Ok |
19 |
Correct |
22 ms |
10988 KB |
Ok |
20 |
Correct |
14 ms |
10348 KB |
Ok |
21 |
Correct |
25 ms |
11116 KB |
Ok |
22 |
Correct |
17 ms |
10604 KB |
Ok |
23 |
Correct |
7 ms |
9708 KB |
Ok |
24 |
Correct |
7 ms |
9708 KB |
Ok |
25 |
Correct |
7 ms |
9708 KB |
Ok |
26 |
Correct |
7 ms |
9708 KB |
Ok |
27 |
Correct |
7 ms |
9728 KB |
Ok |
28 |
Correct |
7 ms |
9708 KB |
Ok |
29 |
Correct |
7 ms |
9708 KB |
Ok |
30 |
Correct |
7 ms |
9708 KB |
Ok |
31 |
Correct |
7 ms |
9708 KB |
Ok |
32 |
Correct |
7 ms |
9708 KB |
Ok |
33 |
Correct |
7 ms |
9708 KB |
Ok |
34 |
Correct |
11 ms |
9964 KB |
Ok |
35 |
Correct |
9 ms |
9964 KB |
Ok |
36 |
Correct |
9 ms |
9964 KB |
Ok |
37 |
Correct |
9 ms |
9964 KB |
Ok |
38 |
Correct |
9 ms |
9964 KB |
Ok |
39 |
Correct |
9 ms |
9964 KB |
Ok |
40 |
Correct |
9 ms |
9836 KB |
Ok |
41 |
Correct |
10 ms |
9964 KB |
Ok |
42 |
Correct |
9 ms |
9964 KB |
Ok |
43 |
Correct |
9 ms |
9964 KB |
Ok |
44 |
Correct |
14 ms |
10220 KB |
Ok |
45 |
Correct |
15 ms |
10220 KB |
Ok |
46 |
Correct |
15 ms |
10348 KB |
Ok |
47 |
Correct |
15 ms |
10220 KB |
Ok |
48 |
Correct |
15 ms |
10220 KB |
Ok |
49 |
Correct |
14 ms |
10220 KB |
Ok |
50 |
Correct |
15 ms |
10220 KB |
Ok |
51 |
Correct |
15 ms |
10220 KB |
Ok |
52 |
Correct |
15 ms |
10348 KB |
Ok |
53 |
Correct |
15 ms |
10220 KB |
Ok |
54 |
Correct |
139 ms |
15716 KB |
Ok |
55 |
Correct |
179 ms |
16104 KB |
Ok |
56 |
Correct |
166 ms |
16228 KB |
Ok |
57 |
Correct |
114 ms |
15084 KB |
Ok |
58 |
Correct |
154 ms |
15592 KB |
Ok |
59 |
Correct |
133 ms |
15208 KB |
Ok |
60 |
Correct |
117 ms |
14692 KB |
Ok |
61 |
Correct |
120 ms |
15332 KB |
Ok |
62 |
Correct |
177 ms |
15844 KB |
Ok |
63 |
Correct |
128 ms |
15212 KB |
Ok |
64 |
Correct |
168 ms |
16252 KB |
Ok |
65 |
Correct |
162 ms |
15716 KB |
Ok |
66 |
Correct |
135 ms |
15592 KB |
Ok |
67 |
Correct |
108 ms |
15336 KB |
Ok |
68 |
Correct |
137 ms |
15588 KB |
Ok |
69 |
Correct |
511 ms |
25316 KB |
Ok |
70 |
Correct |
773 ms |
25956 KB |
Ok |
71 |
Correct |
504 ms |
25444 KB |
Ok |
72 |
Correct |
549 ms |
25188 KB |
Ok |
73 |
Correct |
615 ms |
25528 KB |
Ok |
74 |
Correct |
444 ms |
25060 KB |
Ok |
75 |
Correct |
412 ms |
24676 KB |
Ok |
76 |
Correct |
717 ms |
25444 KB |
Ok |
77 |
Correct |
430 ms |
24676 KB |
Ok |
78 |
Correct |
629 ms |
25316 KB |
Ok |
79 |
Correct |
673 ms |
25460 KB |
Ok |
80 |
Correct |
515 ms |
25572 KB |
Ok |
81 |
Correct |
493 ms |
25316 KB |
Ok |
82 |
Correct |
524 ms |
25452 KB |
Ok |
83 |
Correct |
420 ms |
24932 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9708 KB |
Ok |
2 |
Correct |
7 ms |
9708 KB |
Ok |
3 |
Correct |
7 ms |
9708 KB |
Ok |
4 |
Correct |
7 ms |
9708 KB |
Ok |
5 |
Correct |
7 ms |
9708 KB |
Ok |
6 |
Correct |
7 ms |
9708 KB |
Ok |
7 |
Correct |
7 ms |
9708 KB |
Ok |
8 |
Correct |
7 ms |
9708 KB |
Ok |
9 |
Correct |
7 ms |
9708 KB |
Ok |
10 |
Correct |
7 ms |
9708 KB |
Ok |
11 |
Correct |
7 ms |
9708 KB |
Ok |
12 |
Correct |
7 ms |
9708 KB |
Ok |
13 |
Correct |
7 ms |
9708 KB |
Ok |
14 |
Correct |
7 ms |
9708 KB |
Ok |
15 |
Correct |
7 ms |
9708 KB |
Ok |
16 |
Correct |
7 ms |
9708 KB |
Ok |
17 |
Correct |
7 ms |
9708 KB |
Ok |
18 |
Correct |
10 ms |
9964 KB |
Ok |
19 |
Correct |
22 ms |
10988 KB |
Ok |
20 |
Correct |
14 ms |
10348 KB |
Ok |
21 |
Correct |
25 ms |
11116 KB |
Ok |
22 |
Correct |
17 ms |
10604 KB |
Ok |
23 |
Correct |
7 ms |
9708 KB |
Ok |
24 |
Correct |
7 ms |
9708 KB |
Ok |
25 |
Correct |
7 ms |
9708 KB |
Ok |
26 |
Correct |
7 ms |
9708 KB |
Ok |
27 |
Correct |
7 ms |
9728 KB |
Ok |
28 |
Correct |
7 ms |
9708 KB |
Ok |
29 |
Correct |
7 ms |
9708 KB |
Ok |
30 |
Correct |
7 ms |
9708 KB |
Ok |
31 |
Correct |
7 ms |
9708 KB |
Ok |
32 |
Correct |
7 ms |
9708 KB |
Ok |
33 |
Correct |
7 ms |
9708 KB |
Ok |
34 |
Correct |
7 ms |
9708 KB |
Ok |
35 |
Correct |
7 ms |
9708 KB |
Ok |
36 |
Correct |
7 ms |
9708 KB |
Ok |
37 |
Correct |
7 ms |
9708 KB |
Ok |
38 |
Correct |
7 ms |
9708 KB |
Ok |
39 |
Correct |
289 ms |
28256 KB |
Ok |
40 |
Correct |
305 ms |
30524 KB |
Ok |
41 |
Correct |
603 ms |
33248 KB |
Ok |
42 |
Correct |
378 ms |
30304 KB |
Ok |
43 |
Correct |
179 ms |
21348 KB |
Ok |
44 |
Correct |
309 ms |
31840 KB |
Ok |
45 |
Correct |
11 ms |
9964 KB |
Ok |
46 |
Correct |
9 ms |
9964 KB |
Ok |
47 |
Correct |
9 ms |
9964 KB |
Ok |
48 |
Correct |
9 ms |
9964 KB |
Ok |
49 |
Correct |
9 ms |
9964 KB |
Ok |
50 |
Correct |
9 ms |
9964 KB |
Ok |
51 |
Correct |
9 ms |
9836 KB |
Ok |
52 |
Correct |
10 ms |
9964 KB |
Ok |
53 |
Correct |
9 ms |
9964 KB |
Ok |
54 |
Correct |
9 ms |
9964 KB |
Ok |
55 |
Correct |
14 ms |
10220 KB |
Ok |
56 |
Correct |
15 ms |
10220 KB |
Ok |
57 |
Correct |
15 ms |
10348 KB |
Ok |
58 |
Correct |
15 ms |
10220 KB |
Ok |
59 |
Correct |
15 ms |
10220 KB |
Ok |
60 |
Correct |
14 ms |
10220 KB |
Ok |
61 |
Correct |
15 ms |
10220 KB |
Ok |
62 |
Correct |
15 ms |
10220 KB |
Ok |
63 |
Correct |
15 ms |
10348 KB |
Ok |
64 |
Correct |
15 ms |
10220 KB |
Ok |
65 |
Correct |
139 ms |
15716 KB |
Ok |
66 |
Correct |
179 ms |
16104 KB |
Ok |
67 |
Correct |
166 ms |
16228 KB |
Ok |
68 |
Correct |
114 ms |
15084 KB |
Ok |
69 |
Correct |
154 ms |
15592 KB |
Ok |
70 |
Correct |
133 ms |
15208 KB |
Ok |
71 |
Correct |
117 ms |
14692 KB |
Ok |
72 |
Correct |
120 ms |
15332 KB |
Ok |
73 |
Correct |
177 ms |
15844 KB |
Ok |
74 |
Correct |
128 ms |
15212 KB |
Ok |
75 |
Correct |
168 ms |
16252 KB |
Ok |
76 |
Correct |
162 ms |
15716 KB |
Ok |
77 |
Correct |
135 ms |
15592 KB |
Ok |
78 |
Correct |
108 ms |
15336 KB |
Ok |
79 |
Correct |
137 ms |
15588 KB |
Ok |
80 |
Correct |
511 ms |
25316 KB |
Ok |
81 |
Correct |
773 ms |
25956 KB |
Ok |
82 |
Correct |
504 ms |
25444 KB |
Ok |
83 |
Correct |
549 ms |
25188 KB |
Ok |
84 |
Correct |
615 ms |
25528 KB |
Ok |
85 |
Correct |
444 ms |
25060 KB |
Ok |
86 |
Correct |
412 ms |
24676 KB |
Ok |
87 |
Correct |
717 ms |
25444 KB |
Ok |
88 |
Correct |
430 ms |
24676 KB |
Ok |
89 |
Correct |
629 ms |
25316 KB |
Ok |
90 |
Correct |
673 ms |
25460 KB |
Ok |
91 |
Correct |
515 ms |
25572 KB |
Ok |
92 |
Correct |
493 ms |
25316 KB |
Ok |
93 |
Correct |
524 ms |
25452 KB |
Ok |
94 |
Correct |
420 ms |
24932 KB |
Ok |
95 |
Correct |
315 ms |
25572 KB |
Ok |
96 |
Correct |
571 ms |
32604 KB |
Ok |
97 |
Correct |
610 ms |
28516 KB |
Ok |
98 |
Correct |
345 ms |
28508 KB |
Ok |
99 |
Correct |
481 ms |
28512 KB |
Ok |
100 |
Correct |
557 ms |
27488 KB |
Ok |
101 |
Correct |
529 ms |
30444 KB |
Ok |
102 |
Correct |
483 ms |
28336 KB |
Ok |
103 |
Correct |
501 ms |
29668 KB |
Ok |
104 |
Correct |
631 ms |
31452 KB |
Ok |
105 |
Correct |
603 ms |
31844 KB |
Ok |
106 |
Correct |
429 ms |
32352 KB |
Ok |
107 |
Correct |
526 ms |
30816 KB |
Ok |
108 |
Correct |
643 ms |
31912 KB |
Ok |
109 |
Correct |
546 ms |
33360 KB |
Ok |
110 |
Execution timed out |
2089 ms |
62300 KB |
Time limit exceeded |
111 |
Halted |
0 ms |
0 KB |
- |