#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 * 4 + 222 + 2;
vector<int> g[N];
bool bad = false;
void dfs (int v, vector<int>& used) {
used[v] = 1;
for (auto to : g[v]) {
if (used[to] == 1) {
bad = true;
}
else if (!used[to]) {
dfs (to, used);
}
}
used[v] = -1;
}
bool check (int len, int x, int y) {
bad = false;
vector<int> used (len + 1, false);
for (int i = 0; i <= len; ++i) {
if (i - x >= 0) {
g[i - x].push_back (i);
}
if (i - y >= 0) {
g[i].push_back (i - y);
}
}
for (int i = 0; i <= len; ++i) {
if (!used[i]) {
dfs (i, used);
}
}
for (int i = 0; i <= len; ++i) g[i].clear ();
return !bad;
}
void top (int v, vector<bool>&used, vector<int>&ans) {
used[v] = 1;
for (auto to : g[v]) {
if (!used[to]) {
top (to, used, ans);
}
}
ans.push_back(v);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // LOCAL
int Q;
cin >> Q;
int n = Q;
vector<int> a (n + 1), b (n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i] >> b[i];
if (b[i] % a[i] == 0) {
cout << b[i] - 1 << '\n';
for (int j = 1; j < b[i]; ++j) cout << "-1 ";
cout << "\n";
continue;
}
if (a[i] % b[i] == 0) {
cout << a[i] - 1 << '\n';
for (int j = 1; j < a[i]; ++j) cout << "1 ";
cout << "\n";
continue;
}
int l = a[i] + b[i] - __gcd (a[i], b[i]);
cout << l << '\n';
for (int j = 0; j <= l; ++j) {
if (j - a[i] >= 0) {
g[j - a[i]].push_back (j);
}
if (j - b[i] >= 0) {
g[j].push_back (j - b[i]);
}
}
int cnt = 0;
vector<int> ans;
vector<bool> used (l + 1, false);
for (int j = 0; j <= l; ++j) {
if (!used[j]) {
top (j, used, ans);
}
}
for (int j = 0; j <= l; ++j) g[j].clear();
reverse (begin (ans), end (ans));
vector<int> d (l + 1);
for (auto it : ans) {
d[it] = ++cnt;
}
for (int j = 1; j <= l; ++j) {
cout << d[j] - d[j - 1] << ' ';
}
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9816 KB |
Ok |
2 |
Correct |
4 ms |
9816 KB |
Ok |
3 |
Correct |
4 ms |
9820 KB |
Ok |
4 |
Correct |
4 ms |
9856 KB |
Ok |
5 |
Correct |
4 ms |
9820 KB |
Ok |
6 |
Correct |
4 ms |
9820 KB |
Ok |
7 |
Correct |
4 ms |
9820 KB |
Ok |
8 |
Correct |
6 ms |
9860 KB |
Ok |
9 |
Correct |
4 ms |
9828 KB |
Ok |
10 |
Correct |
4 ms |
9820 KB |
Ok |
11 |
Correct |
6 ms |
9860 KB |
Ok |
12 |
Correct |
6 ms |
9820 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
9840 KB |
there is incorrect sequence |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
9820 KB |
there is incorrect sequence |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
9820 KB |
there is incorrect sequence |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9816 KB |
Ok |
2 |
Correct |
4 ms |
9816 KB |
Ok |
3 |
Correct |
4 ms |
9820 KB |
Ok |
4 |
Correct |
4 ms |
9856 KB |
Ok |
5 |
Correct |
4 ms |
9820 KB |
Ok |
6 |
Correct |
4 ms |
9820 KB |
Ok |
7 |
Correct |
4 ms |
9820 KB |
Ok |
8 |
Correct |
6 ms |
9860 KB |
Ok |
9 |
Correct |
4 ms |
9828 KB |
Ok |
10 |
Correct |
4 ms |
9820 KB |
Ok |
11 |
Correct |
6 ms |
9860 KB |
Ok |
12 |
Correct |
6 ms |
9820 KB |
Ok |
13 |
Incorrect |
5 ms |
9820 KB |
there is incorrect sequence |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9816 KB |
Ok |
2 |
Correct |
4 ms |
9816 KB |
Ok |
3 |
Correct |
4 ms |
9820 KB |
Ok |
4 |
Correct |
4 ms |
9856 KB |
Ok |
5 |
Correct |
4 ms |
9820 KB |
Ok |
6 |
Correct |
4 ms |
9820 KB |
Ok |
7 |
Correct |
4 ms |
9820 KB |
Ok |
8 |
Correct |
6 ms |
9860 KB |
Ok |
9 |
Correct |
4 ms |
9828 KB |
Ok |
10 |
Correct |
4 ms |
9820 KB |
Ok |
11 |
Correct |
6 ms |
9860 KB |
Ok |
12 |
Correct |
6 ms |
9820 KB |
Ok |
13 |
Incorrect |
6 ms |
9840 KB |
there is incorrect sequence |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
9816 KB |
Ok |
2 |
Correct |
4 ms |
9816 KB |
Ok |
3 |
Correct |
4 ms |
9820 KB |
Ok |
4 |
Correct |
4 ms |
9856 KB |
Ok |
5 |
Correct |
4 ms |
9820 KB |
Ok |
6 |
Correct |
4 ms |
9820 KB |
Ok |
7 |
Correct |
4 ms |
9820 KB |
Ok |
8 |
Correct |
6 ms |
9860 KB |
Ok |
9 |
Correct |
4 ms |
9828 KB |
Ok |
10 |
Correct |
4 ms |
9820 KB |
Ok |
11 |
Correct |
6 ms |
9860 KB |
Ok |
12 |
Correct |
6 ms |
9820 KB |
Ok |
13 |
Incorrect |
6 ms |
9840 KB |
there is incorrect sequence |
14 |
Halted |
0 ms |
0 KB |
- |