結果

問題 No.1837 Same but Different
ユーザー 👑 hitonanodehitonanode
提出日時 2021-12-12 13:00:03
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 2,123 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 94,532 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-28 05:06:50
合計ジャッジ時間 2,813 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 28 ms
4,380 KB
testcase_05 AC 28 ms
4,380 KB
testcase_06 AC 29 ms
4,380 KB
testcase_07 AC 28 ms
4,376 KB
testcase_08 AC 30 ms
4,376 KB
testcase_09 AC 28 ms
4,380 KB
testcase_10 AC 29 ms
4,376 KB
testcase_11 AC 28 ms
4,376 KB
testcase_12 AC 28 ms
4,376 KB
testcase_13 AC 30 ms
4,500 KB
testcase_14 AC 28 ms
4,380 KB
testcase_15 AC 6 ms
4,376 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 12 ms
4,376 KB
testcase_19 AC 9 ms
4,380 KB
testcase_20 AC 6 ms
4,376 KB
testcase_21 AC 9 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 6 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bitset>
#include <cassert>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

void validator(int N, const vector<int> &A, const vector<int> &B) {
    assert(A.size() == N);
    assert(B.size() == N);
    for (auto &x : A) assert(x >= 0 and x <= 10000);
    for (auto &x : B) assert(x >= 0 and x <= 10000);
    bitset<10000 * 2 + 1> bs;
    for (int i = 0; i < N - 1; ++i) {
        assert(A[i] < A[i + 1]);
        assert(B[i] < B[i + 1]);
    }
    for (auto a : A) {
        for (auto b : A) bs.set(a + b);
    }
    for (auto a : B) {
        for (auto b : B) {
            if (bs[a + b]) {
                cerr << a << ' ' << b << endl;
                throw;
            }
        }
    }
    assert(accumulate(A.begin(), A.end(), 0LL) == accumulate(B.begin(), B.end(), 0LL));
}

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N;
    cin >> N;
    if (N == 4) {
        puts("1 2 3 120");
        puts("30 31 32 33");
        return 0;
    }
    int p = 3;
    // [0, 0, 0, 0, ..., 0] vs. [1, 1, 1, 1, ..., -(N - 1)]
    // while ((N - 2) % p == 0) ++p;
    vector<int> A{3}, B{7};
    if ((N - 2) % p == 0) A[0]++;
    for (int i = 10; i <= 10000; ++i) {
        if (i % p == 0 and int(A.size()) < N) A.push_back(i);
        if (i % p == 1 and int(B.size()) < N - 1) B.push_back(i);
    }
    B.push_back(accumulate(A.begin(), A.end(), 0LL) - accumulate(B.begin(), B.end(), 0LL));

    while (B.back() > 10000) {
        for (int i = N - 2; i >= 0; --i) {
            while (B[i] + 3 < 9900 and B[i] + 3 < B.back() - 3 and B.back() > 10000) {
                if (i + 1 < N and B[i] + 3 >= B[i + 1]) break;
                B[i] += 3;
                B.back() -= 3;
            }
        }
    }
    for (int i = 0; i < N; ++i) cout << A[i] << (i + 1 == N ? '\n' : ' ');
    for (int i = 0; i < N; ++i) cout << B[i] << (i + 1 == N ? '\n' : ' ');
    validator(N, A, B);
    // cerr << p << endl;
    // cerr << A.size() << ' ' << accumulate(A.begin(), A.end(), 0LL) << '\n';
    // cerr << B.size() << ' ' << accumulate(B.begin(), B.end(), 0LL) << '\n';
}
0