結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 10 ms
4,348 KB
testcase_02 AC 11 ms
4,348 KB
testcase_03 AC 11 ms
4,348 KB
testcase_04 AC 11 ms
4,348 KB
testcase_05 AC 11 ms
4,348 KB
testcase_06 AC 5 ms
4,348 KB
testcase_07 AC 6 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 5 ms
4,348 KB
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 5 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 5 ms
4,348 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 17 ms
5,104 KB
testcase_17 AC 10 ms
4,348 KB
testcase_18 AC 10 ms
4,348 KB
testcase_19 AC 9 ms
4,348 KB
testcase_20 AC 12 ms
4,576 KB
testcase_21 AC 14 ms
5,180 KB
testcase_22 AC 15 ms
5,180 KB
testcase_23 AC 17 ms
5,104 KB
testcase_24 AC 14 ms
4,840 KB
testcase_25 AC 14 ms
4,840 KB
testcase_26 AC 14 ms
4,840 KB
testcase_27 AC 14 ms
5,368 KB
testcase_28 AC 15 ms
5,368 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]) {
            if (arr[prv] == 0)
                return cout << "No\n", void();
            if (!--arr[prv]) q.push(prv);
        }
        if (!done[nxt]) {
            if (arr[nxt] == 0)
                return cout << "No\n", void();
            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