답안 #879332

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879332 2023-11-27T07:05:03 Z The_Samurai Nice sequence (IZhO18_sequence) C++17
15 / 100
6 ms 1268 KB
// I stand with PALESTINE




//#pragma GCC optimize("Ofast,O3")
//#pragma GCC target("avx,avx2")
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const int inf = 1e9;

random_device rd;
mt19937 mt(rd());

int rand(int l, int r) {
    uniform_int_distribution<int> dist(l, r);
    return dist(mt);
};

void out(vector<int> a, bool minus = false) {
    cout << a.size() << '\n';
    if (a.empty()) return;
    for (int x: a) cout << x * (minus ? -1 : 1) << ' ';
    cout << '\n';
}

int nn, mm;
vector<int> solve(int n, int m) {
    // n >= m
    if (n % m == 0) return vector(n - 1, 1);
    if (m == 2) {
        vector<int> a(n);
        for (int i = 0; i < n; i++) a[i] = i % 2 ? inf : -(inf - 1);
        return a;
    }
    vector<int> a(m - 1, -100);
    int ln = m - 1;
    while (true) {
        ll lxm = -1000 * ln * m, rxm = 1000 * ln * m;
        ll lxp = -1000 * ln * m, rxp = 1000 * ln * m;
        if (ln >= m - 1) {
            ll sum = 0;
            for (int i = ln - m + 1; i < ln; i++) sum += a[i];
            // sum + x >= 0
            // x >= -sum
            lxp = max(lxp, -sum);
        }
        if (ln >= n - 1) {
            ll sum = 0;
            for (int i = ln - n + 1; i < ln; i++) sum += a[i];
            rxm = min(rxm, -sum);
        }
        ll l = max(lxm, lxp), r = min(rxm, rxp);
        if (l > r) break;
        a.emplace_back(rand(l, r));
        ln++;
    }
    return a;
}

void solve() {
    int n, m;
    cin >> n >> m;
    if (n >= m) out(solve(n, m));
    else out(solve(m, n), true);
}

int main() {
    cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int q = 1;
    cin >> q;
    while (q--) {
        solve();
//        cout << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 344 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 344 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 348 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 600 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 1 ms 348 KB Ok
7 Correct 5 ms 860 KB Ok
8 Correct 3 ms 604 KB Ok
9 Correct 6 ms 1268 KB Ok
10 Correct 4 ms 828 KB Ok
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Incorrect 0 ms 344 KB Jury has the better answer : jans = 9, pans = 7
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Jury has the better answer : jans = 6, pans = 5
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 344 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 344 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 348 KB Ok
13 Correct 0 ms 348 KB Ok
14 Correct 0 ms 348 KB Ok
15 Correct 0 ms 348 KB Ok
16 Incorrect 0 ms 344 KB Jury has the better answer : jans = 9, pans = 7
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 344 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 344 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 348 KB Ok
13 Correct 0 ms 344 KB Ok
14 Correct 0 ms 348 KB Ok
15 Correct 0 ms 600 KB Ok
16 Correct 0 ms 348 KB Ok
17 Correct 0 ms 348 KB Ok
18 Correct 1 ms 348 KB Ok
19 Correct 5 ms 860 KB Ok
20 Correct 3 ms 604 KB Ok
21 Correct 6 ms 1268 KB Ok
22 Correct 4 ms 828 KB Ok
23 Correct 0 ms 348 KB Ok
24 Correct 0 ms 348 KB Ok
25 Correct 0 ms 348 KB Ok
26 Incorrect 0 ms 344 KB Jury has the better answer : jans = 9, pans = 7
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 344 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 344 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 348 KB Ok
13 Correct 0 ms 344 KB Ok
14 Correct 0 ms 348 KB Ok
15 Correct 0 ms 600 KB Ok
16 Correct 0 ms 348 KB Ok
17 Correct 0 ms 348 KB Ok
18 Correct 1 ms 348 KB Ok
19 Correct 5 ms 860 KB Ok
20 Correct 3 ms 604 KB Ok
21 Correct 6 ms 1268 KB Ok
22 Correct 4 ms 828 KB Ok
23 Correct 0 ms 348 KB Ok
24 Correct 0 ms 348 KB Ok
25 Correct 0 ms 348 KB Ok
26 Incorrect 0 ms 344 KB Jury has the better answer : jans = 9, pans = 7
27 Halted 0 ms 0 KB -