結果
| 問題 | No.3783 Choose Disjoint Semicircles |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-27 02:14:06 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 1,613 bytes |
| 記録 | |
| コンパイル時間 | 2,470 ms |
| コンパイル使用メモリ | 340,000 KB |
| 実行使用メモリ | 9,816 KB |
| 平均クエリ数 | 66.81 |
| 最終ジャッジ日時 | 2026-10-30 20:53:42 |
| 合計ジャッジ時間 | 7,654 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 WA * 29 |
ソースコード
//generated by ChatGPT
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
// 失敗時には次の N の代わりに -1 が入力される。
if (N == -1) {
return 0;
}
vector<int> P(N);
vector<int> pos(N + 1);
for (int i = 0; i < N; ++i) {
cin >> P[i];
pos[P[i]] = i;
}
const int M = N / 2;
const int s = pos[1];
// 1 の反対側にある値。
const int opposite_value = P[(s + M) % N];
// 2 が反対側なら 3、そうでなければ 2。
const int q = (opposite_value == 2 ? 3 : 2);
// 値 1 から正方向に M 個取る区間に q が入っているか。
const int clockwise_distance = (pos[q] - s + N) % N;
int k;
if (clockwise_distance < M) {
// A = [s, s + M - 1]
k = s;
} else {
// A = [s - M + 1, s]
k = (s - M + 1 + N) % N;
}
const int b_start = (k + M) % N;
const int a_first = P[k];
const int a_last = P[(k + M - 1) % N];
const int b_first = P[b_start];
const int b_last = P[(b_start + M - 1) % N];
const bool uA = (a_first > a_last);
const bool uB = (b_first > b_last);
const bool bit = uA ^ uB;
const int answer = bit ? b_start : k;
cout << answer << endl; // endl により flush される。
}
return 0;
}