Submission #1085282

# Submission time Handle Problem Language Result Execution time Memory
1085282 2024-09-07T20:38:09 Z zxcigan Nice sequence (IZhO18_sequence) C++17
0 / 100
5 ms 9820 KB
#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]);
        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
1 Incorrect 4 ms 9820 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 9636 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 9816 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 9820 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 9820 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 9820 KB there is incorrect sequence
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 9820 KB there is incorrect sequence
2 Halted 0 ms 0 KB -