結果
問題 | No.2518 Adjacent Larger |
ユーザー |
|
提出日時 | 2023-10-27 21:47:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 1,137 bytes |
コンパイル時間 | 2,147 ms |
コンパイル使用メモリ | 198,368 KB |
最終ジャッジ日時 | 2025-02-17 14:50:45 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 28 |
ソースコード
#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_backvoid 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();}}