# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90509 | Just_Solve_The_Problem | Nice sequence (IZhO18_sequence) | C++11 | 609 ms | 43728 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>
using namespace std;
const int N = (int)4e5 + 7;
int used[N];
int tiktak, n, m, len;
int tout[N];
void dfs(int v) {
used[v] = 1;
if (v > m && !used[v - m]) {
dfs(v - m);
}
if (v + n <= len && !used[v + n]) {
dfs(v + n);
}
tiktak++;
tout[v] = tiktak;
}
void solve() {
int tiktak = 0;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n + m; i++) {
used[i] = 0;
}
if (n == m) {
printf("%d\n", n - 1);
for (int i = 1; i < n; i++) {
printf("1 ");
}
puts("");
return ;
}
len = n + m - __gcd(n, m);
for (int i = 1; i <= len; i++) {
if (!used[i]) {
dfs(i);
}
}
printf("%d\n", len - 1);
for (int i = 1; i < len; i++) {
printf("%d ", tout[i + 1] - tout[i]);
}
puts("");
}
main() {
int test;
scanf("%d", &test);
while (test--) {
solve();
}
}
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... |