This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 * 4 + 222 + 2;
vector<int> g[N];
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];
int l = a[i] + b[i] - __gcd (a[i], b[i]) - 1;
swap (a[i], b[i]);
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]);
}
}
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 (int j = 0; j <= l; ++j) {
d[ans[j]] = j;
}
cout << l << '\n';
for (int j = 1; j <= l; ++j) {
cout << d[j] - d[j - 1] << ' ';
}
cout << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |