結果

問題 No.2518 Adjacent Larger
ユーザー baluteshihbaluteshih
提出日時 2023-10-27 21:45:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,069 bytes
コンパイル時間 2,217 ms
コンパイル使用メモリ 207,268 KB
実行使用メモリ 5,292 KB
最終ジャッジ日時 2023-10-27 21:45:24
合計ジャッジ時間 3,290 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 5 ms
4,348 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 6 ms
4,348 KB
testcase_10 WA -
testcase_11 AC 6 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 6 ms
4,348 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 20 ms
5,028 KB
testcase_17 AC 12 ms
4,348 KB
testcase_18 AC 12 ms
4,348 KB
testcase_19 AC 10 ms
4,348 KB
testcase_20 AC 15 ms
4,500 KB
testcase_21 AC 16 ms
5,108 KB
testcase_22 AC 16 ms
5,108 KB
testcase_23 AC 20 ms
5,028 KB
testcase_24 AC 16 ms
4,764 KB
testcase_25 AC 17 ms
4,764 KB
testcase_26 AC 17 ms
4,764 KB
testcase_27 AC 15 ms
5,292 KB
testcase_28 AC 17 ms
5,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
#define pb push_back

void solve() {
    int n;
    cin >> n;
    vector<int> arr(n), done(n);
    for (int &i : arr)
        cin >> i;

    queue<int> q;

    for (int i = 0; i < n; ++i)
        if (arr[i] == 0)
            q.push(i);

    int cnt = 0;
    while (!q.empty()) {
        int u = q.front();
        q.pop(), ++cnt;
        int prv = (u + n - 1) % n;
        int nxt = (u + 1) % n;
        if (!done[prv] && arr[prv] == 0)
            return cout << "No\n", void();
        if (!done[nxt] && arr[nxt] == 0)
            return cout << "No\n", void();
        if (!--arr[prv]) q.push(prv);
        if (!--arr[nxt]) q.push(nxt);
        done[u] = 1;
    }
    if (cnt < n) cout << "No\n";
    else cout << "Yes\n";
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}
0