結果

問題 No.3783 Choose Disjoint Semicircles
コンテスト
ユーザー askr58
提出日時 2026-07-28 08:27:21
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 428 ms / 2,000 ms
+ 999µs
コード長 1,555 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,894 ms
コンパイル使用メモリ 338,832 KB
実行使用メモリ 9,776 KB
平均クエリ数 4493.62
最終ジャッジ日時 2026-10-30 20:54:34
合計ジャッジ時間 14,085 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

//generated by ChatGPT

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

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

    int Q;
    cin >> Q;

    while (Q--) {
        int N;
        cin >> N;

        if (N == -1) {
            return 0;
        }

        vector<int> P(N);
        int pos1 = -1;

        for (int i = 0; i < N; ++i) {
            cin >> P[i];
            if (P[i] == 1) {
                pos1 = i;
            }
        }

        // 値 1 の位置から d だけ進んだ場所の値
        auto value_at = [&](int d) -> int {
            return P[(pos1 + d) % N];
        };

        int offset;

        if (N == 6) {
            bool u = value_at(2) < value_at(4);
            bool v = value_at(1) < value_at(5);

            offset = (u ^ v) ? 2 : 5;
        } else {
            int M = N / 2;

            const array<int, 4> position = {
                M + 1,
                2,
                M - 1,
                N - 2
            };

            const array<int, 4> answer_offset = {
                0,
                1,
                M + 1,
                M
            };

            int best = 0;
            for (int c = 1; c < 4; ++c) {
                if (value_at(position[c]) <
                    value_at(position[best])) {
                    best = c;
                }
            }

            offset = answer_offset[best];
        }

        int answer = (pos1 + offset) % N;

        // endl によって flush する
        cout << answer << endl;
    }

    return 0;
}
0