結果

問題 No.3728 Half and Half, and Double
コンテスト
ユーザー 👑 kencho
提出日時 2026-07-02 09:58:49
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 2,000 ms
+ 166µs
コード長 1,512 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,232 ms
コンパイル使用メモリ 336,472 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-19 12:31:34
合計ジャッジ時間 4,960 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

vector<string> build(int n) {
    int size = 2 * n;
    if (n == 3) {
        return {
            "AAAAAA",
            "ABBBAA",
            "ABBBBA",
            "ABBBBA",
            "ABBBBA",
            "ABBBAA"
        };
    }
    if (n == 4) {
        return {
            "AAAAAAAA",
            "AAAAAAAA",
            "ABBBBAAA",
            "ABBBBBBA",
            "ABBBBBBA",
            "ABBBBBBA",
            "ABBBBBBA",
            "ABBBBAAA"
        };
    }

    int squareSize = 2 * n - 3;
    vector<string> grid(size, string(size, 'A'));

    grid[0][0] = 'B';
    grid[0][1] = 'B';
    grid[1][0] = 'B';

    for (int row = 1; row <= squareSize; row++) {
        for (int col = 1; col <= squareSize; col++) {
            grid[row][col] = 'B';
        }
    }

    long long removeCount = 1LL * squareSize * squareSize + 3 - 2LL * n * n;
    for (int row = squareSize; removeCount > 0; row--) {
        int take = static_cast<int>(min<long long>(squareSize - 1, removeCount));
        for (int col = squareSize - take + 1; col <= squareSize; col++) {
            grid[row][col] = 'A';
        }
        removeCount -= take;
    }

    return grid;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    if (n <= 2) {
        cout << -1 << '\n';
        return 0;
    }

    vector<string> grid = build(n);
    for (const string& row : grid) {
        cout << row << '\n';
    }

    return 0;
}
0