# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40508 | Akylbek | Nice sequence (IZhO18_sequence) | C++14 | 1743 ms | 73296 KiB |
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>
#define ll long long
#define pb push_back
using namespace std;
const int N = 4e5 + 10;
const int md = 1e9 + 7;
int T;
int n, m;
vector <int> g[N];
int p[N];
int used[N];
vector <int> ord;
void dfs (int v) {
used[v] = 1;
for (auto to : g[v]) {
if (!used[to]) dfs(to);
}
ord.pb(v);
}
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
int len = n + m - __gcd(n, m) - 1;
for (int i = n; i <= len; i++) {
g[i - n].pb(i);
}
for (int i = m; i <= len; i++) {
g[i].pb(i - m);
}
for (int i = 0; i <= len; i++) {
if (!used[i]) {
dfs(i);
}
}
for (int i = 0; i < len + 1; i++) {
if (ord[i] == 0) {
p[ord[i]] = 0;
continue;
}
if (i == 0) {
p[ord[i]] = -1000000;
continue;
}
p[ord[i]] = p[ord[i - 1]] + 1;
}
cout << len << '\n';
for (int i = 1; i <= len; i++) {
cout << p[i] - p[i - 1] << ' ';
}
cout << '\n';
for (int i = 0; i <= len; i++) {
g[i].clear();
used[i] = 0;
}
ord.clear();
}
return 0;
}
Compilation message (stderr)
# | 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... |