結果

問題 No.2860 Heal Slimes
ユーザー tottoripaper
提出日時 2024-08-28 03:23:57
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 2,339 bytes
コンパイル時間 3,526 ms
コンパイル使用メモリ 253,824 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-28 03:24:08
合計ジャッジ時間 8,122 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define snd(t) std::get<1>(t)

using ll = std::int64_t;

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int T;
    std::cin >> T;

    for(int _=0;_<T;_++){
        int N, K, X;
        std::cin >> N >> K >> X;

        std::vector<int> H(N + 2, 0);
        for(int i=1;i<=N;i++){
            std::cin >> H[i];
        }

        std::vector<int> D(N + 2, 0);
        for(int i=1;i<=N+1;i++){
            D[i] = H[i - 1] - H[i];
        }

        bool ok = true;
        for(int i=0;i<K;i++){
            bool leftVacancy = false;
            bool rightVacancy = false;
            std::vector<int> I;
            for(int j=1+i;j<=N+1;j+=K){
                if(j == 1){
                    leftVacancy = true;
                }else if(j == N + 1){
                    rightVacancy = true;
                }else{
                    I.emplace_back(j);
                }
            }

            if(leftVacancy && rightVacancy){
                for(auto j : I){
                    if(D[j] % X != 0){
                        ok = false;
                        break;
                    }
                }
            }else if(leftVacancy){
                ll sum = 0;
                for(auto j : std::ranges::views::reverse(I)){
                    sum += D[j];
                    if(sum % X != 0 || sum > 0){
                        ok = false;
                        break;
                    }
                }
            }else if(rightVacancy){
                ll sum = 0;
                for(auto j : I){
                    sum += D[j];
                    if(sum % X != 0 || sum < 0){
                        ok = false;
                        break;
                    }
                }
            }else{
                ll sum = 0;
                for(auto j : I){
                    sum += D[j];
                    if(sum % X != 0 || sum < 0){
                        ok = false;
                        break;
                    }
                }

                if(sum != 0){
                    ok = false;
                    break;
                }
            }

            if(!ok){break;}
        }

        if(ok){
            std::cout << "Yes" << std::endl;
        }else{
            std::cout << "No" << std::endl;
        }
    }
}
0