結果

問題 No.2518 Adjacent Larger
ユーザー mhal-teddy
提出日時 2023-10-28 05:00:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,316 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 74,348 KB
最終ジャッジ日時 2025-02-17 16:33:13
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

int main() {
    int t;
    std::cin >> t;

    for (int i = 0; i < t; i++) {
        int n;
        std::cin >> n;
        std::vector<int> a(n);
        for (int j = 0; j < n; j++) {
            std::cin >> a.at(j);
        }

        // 2となる位置
        int index = -1;
        for (int j = 0; j < n; j++) {
            if (a.at(j) == 2) {
                index = j;
                break;
            }
        }
        if (index == -1) {
            std::cout << "No" << std::endl;
        } else {
            std::vector<char> to(n);
            for (int j = index; j < index + n; j++) {
                int k = j % n;
                if (a.at(k) == 0) to.at(k) = '>';
                else if (a.at(k) == 2) to.at(k) = '<';
                else to.at(k) = to.at((k - 1 + n) % n);
            }

            bool flag = true;
            for (int j = 0; j < n; j++) {
                int count = 0;
                if (to.at((j - 1 + n) % n) == '>') count++;
                if (to.at(j) == '<') count++;
                if (a.at(j) != count) {
                    std::cout << "No" << std::endl;
                    flag = false;
                    break;
                }
            }
            if (flag) std::cout << "Yes" << std::endl;
        }
    }
}
0