Submission #1085278

# Submission time Handle Problem Language Result Execution time Memory
1085278 2024-09-07T20:22:59 Z zxcigan Nice sequence (IZhO18_sequence) C++17
6 / 100
5 ms 9900 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int N = 1e5 * 4 + 222 + 2;

vector<int> g[N];
bool bad = false;
void dfs (int v, vector<int>& used) {
    used[v] = 1;
    for (auto to : g[v]) {
        if (used[to] == 1) {
            bad = true;
        }
        else if (!used[to]) {
            dfs (to, used);
        }
    }
    used[v] = -1;
}
bool check (int len, int x, int y) {
    bad = false;
    vector<int> used (len + 1, false);
    for (int i = 0; i <= len; ++i) {
        if (i - x >= 0) {
            g[i - x].push_back (i);
        }
        if (i - y >= 0) {
            g[i].push_back (i - y);
        }
    }
    for (int i = 0; i <= len; ++i) {
        if (!used[i]) {
            dfs (i, used);
        }
    }
    for (int i = 0; i <= len; ++i) g[i].clear ();
    return !bad;
}
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;
//    for (int x = 1; x <= 10; ++x) {
//        for (int y = 1; y <= 10; ++y){
//            int l = max (x, y) - 1, r = max (y, x) * 4;
//            while (l < r) {
//                int mid  = (r + l + 1) >> 1;
//                if (check (mid, x, y)) l = mid;
//                else r = mid - 1;
//            }
//            cout << x << ' ' << y << ' ' << l << '\n';
//        }
//    }
//    return 0;
    vector<int> a (n + 1), b (n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i] >> b[i];
        if (b[i] % a[i] == 0) {
            cout << b[i] - 1 << '\n';
            for (int j = 1; j < b[i]; ++j) cout << "-1 ";
            cout << "\n";
            continue;
        }
        if (a[i] % b[i] == 0) {
            cout << a[i] - 1 << '\n';
            for (int j = 1; j < a[i]; ++j) cout << "1 ";
            cout << "\n";

            continue;
        }
        int l = max (a[i], b[i]) - 1, r = max (a[i], b[i]) * 4;
        while (l < r) {
            int mid  = (r + l + 1) >> 1;
            if (check (mid, a[i], b[i])) l = mid;
            else r = mid - 1;
        }
        cout << l << '\n';
        for (int j = 0; j <= l; ++j) g[j].clear();
        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]);
            }
        }
        int cnt = 0;
        vector<int> ans;
        vector<bool> used (l + 1, false);
        for (int j = 0; j <= l; ++j) {
            if (!used[j]) {
                top (j, used, ans);
            }
        }
        reverse (begin (ans), end (ans));
        vector<int> d (l + 2);
        for (auto it : ans) {
            d[it] = cnt++;
        }
        for (int j = 1; j <= l; ++j) cout << d[j] - d[j - 1] <<  ' ';
        cout << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Ok
2 Correct 4 ms 9820 KB Ok
3 Correct 4 ms 9820 KB Ok
4 Correct 4 ms 9764 KB Ok
5 Correct 4 ms 9816 KB Ok
6 Correct 4 ms 9816 KB Ok
7 Correct 4 ms 9816 KB Ok
8 Correct 4 ms 9816 KB Ok
9 Correct 4 ms 9820 KB Ok
10 Correct 4 ms 9852 KB Ok
11 Correct 5 ms 9900 KB Ok
12 Correct 4 ms 9820 KB Ok
# 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 Correct 4 ms 9820 KB Ok
2 Correct 4 ms 9820 KB Ok
3 Correct 4 ms 9820 KB Ok
4 Correct 4 ms 9764 KB Ok
5 Correct 4 ms 9816 KB Ok
6 Correct 4 ms 9816 KB Ok
7 Correct 4 ms 9816 KB Ok
8 Correct 4 ms 9816 KB Ok
9 Correct 4 ms 9820 KB Ok
10 Correct 4 ms 9852 KB Ok
11 Correct 5 ms 9900 KB Ok
12 Correct 4 ms 9820 KB Ok
13 Incorrect 4 ms 9820 KB there is incorrect sequence
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Ok
2 Correct 4 ms 9820 KB Ok
3 Correct 4 ms 9820 KB Ok
4 Correct 4 ms 9764 KB Ok
5 Correct 4 ms 9816 KB Ok
6 Correct 4 ms 9816 KB Ok
7 Correct 4 ms 9816 KB Ok
8 Correct 4 ms 9816 KB Ok
9 Correct 4 ms 9820 KB Ok
10 Correct 4 ms 9852 KB Ok
11 Correct 5 ms 9900 KB Ok
12 Correct 4 ms 9820 KB Ok
13 Incorrect 4 ms 9816 KB there is incorrect sequence
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Ok
2 Correct 4 ms 9820 KB Ok
3 Correct 4 ms 9820 KB Ok
4 Correct 4 ms 9764 KB Ok
5 Correct 4 ms 9816 KB Ok
6 Correct 4 ms 9816 KB Ok
7 Correct 4 ms 9816 KB Ok
8 Correct 4 ms 9816 KB Ok
9 Correct 4 ms 9820 KB Ok
10 Correct 4 ms 9852 KB Ok
11 Correct 5 ms 9900 KB Ok
12 Correct 4 ms 9820 KB Ok
13 Incorrect 4 ms 9816 KB there is incorrect sequence
14 Halted 0 ms 0 KB -