# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
170547 | 2019-12-25T15:33:38 Z | SamAnd | Nice sequence (IZhO18_sequence) | C++17 | 76 ms | 12704 KB |
#include <bits/stdc++.h> using namespace std; const int N = 300005; int ka() { int x = 0; while (1) { char y = getchar(); if ('0' <= y && y <= '9') x = (x * 10) + (y - '0'); else return x; } } char uu[12]; void tp(int x) { if (x == 0) { putchar('0'); return; } if (x < 0) { putchar('-'); x *= (-1); } int i = 0; while (x) { uu[i++] = (x % 10) + '0'; x /= 10; } for (i = i - 1; i >= 0; --i) putchar(uu[i]); } int n, m; vector<int> a[N]; int c[N]; bool dfs(int x) { c[x] = 1; for (int i = 0; i < a[x].size(); ++i) { int h = a[x][i]; if (c[h] == 1) return true; if (c[h] == 0) if (dfs(h)) return true; } c[x] = 2; return false; } bool stg(int x) { for (int i = 0; i <= x; ++i) a[i].clear(); for (int i = 0; i <= x; ++i) { if (i + m <= x) a[i + m].push_back(i); if (i + n <= x) a[i].push_back(i + n); } for (int i = 0; i <= x; ++i) c[i] = 0; for (int i = 0; i <= x; ++i) { if (dfs(i)) return false; } return true; } vector<int> v; void dfs1(int x) { c[x] = 1; for (int i = 0; i < a[x].size(); ++i) { int h = a[x][i]; if (c[h]) continue; dfs1(h); } v.push_back(x); } int p[N]; void solv() { n = ka(); m = ka(); int l = min(n, m) - 1, r = N - 1; int ans; while (l <= r) { int m = (l + r) / 2; if (stg(m)) { ans = m; l = m + 1; } else r = m - 1; } tp(ans); putchar('\n'); //return; for (int i = 0; i <= ans; ++i) a[i].clear(); for (int i = 0; i <= ans; ++i) { if (i + m <= ans) a[i + m].push_back(i); if (i + n <= ans) a[i].push_back(i + n); } v.clear(); for (int i = 0; i <= ans; ++i) c[i] = 0; for (int i = 0; i <= ans; ++i) { if (!c[i]) dfs1(i); } for (int i = 0; i < v.size(); ++i) p[v[i]] = i; for (int i = 1; i <= ans; ++i) { tp(p[i] - p[i - 1]); putchar(' '); } putchar('\n'); } int main() { int tt; tt = ka(); while (tt--) { solv(); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 76 ms | 12704 KB | Jury has the better answer : jans = 0, pans = -1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 76 ms | 12664 KB | Jury has the better answer : jans = 1, pans = -1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 40 ms | 12664 KB | Jury has the better answer : jans = 2, pans = -1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 74 ms | 12664 KB | Jury has the better answer : jans = 3, pans = -1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 76 ms | 12704 KB | Jury has the better answer : jans = 0, pans = -1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 76 ms | 12704 KB | Jury has the better answer : jans = 0, pans = -1 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 76 ms | 12704 KB | Jury has the better answer : jans = 0, pans = -1 |
2 | Halted | 0 ms | 0 KB | - |