Submission #1101019

# Submission time Handle Problem Language Result Execution time Memory
1101019 2024-10-15T09:58:25 Z Kirill22 Binary Subsequences (info1cup17_binary) C++17
82 / 100
239 ms 98124 KB
#include "bits/stdc++.h"

using namespace std;

const int mod = (int) 1e9 + 7;
const int N = (int) 5e3;
int mem[N][N];

int get(int a, int b) {
    if (a > b) {
        swap(a, b);
    }
    if (a < 0 || b < 0) {
        return -1;
    }
    if (a == 0 && b == 0) {
        return 0;
    }
    if (a == b) {
        return -1;
    }
    if (a < N && b < N && mem[a][b]) {
        return mem[a][b];
    }
    int add = b / (a + 1);
    b %= (a + 1);
    int res = get(a, b);
    if (res == -1) {
        if (a < N && b < N) {
            mem[a][b] = -1;
        }
        return -1;
    }
    if (a < N && b < N) {
        mem[a][b] = res + add;
    }
    return res + add;
}

int phi(int x) {
    int res = x;
    for (int i = 2; i <= x; i++) {
        if (x % i == 0) {
            res -= res / i;
            while (x % i == 0) {
                x /= i;
            }
        }
    }
    return res;
}

void solve() {
    int k;
    cin >> k;
    cout << phi(k + 2) << '\n';
    k++;
    int optj = -1;
    for (int j = 0; j < min(k, 100000); j++) {
        int res = get(j, k - j - 1);
        if (res != -1) {
            if (optj == -1 || res < get(optj, k - optj - 1)) {
                optj = j;
            }
        }
    }
//    cout << optj << endl;
//    return;
//    cout << ans << '\n';
//    exit(0);
    {
        int a = optj, b = k - optj - 1, x = 0;
        while (a + b) {
            if (a > b) {
                x ^= 1;
                swap(a, b);
            }
            while (b >= a + 1) {
                cout << x << " ";
                b -= a + 1;
            }
        }
    }
    cout << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 212 ms 5704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 97864 KB Output is correct
2 Correct 220 ms 98120 KB Output is correct
3 Correct 221 ms 98124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 239 ms 98020 KB Output isn't correct
2 Halted 0 ms 0 KB -