結果

問題 No.2860 Heal Slimes
ユーザー dyktr_06dyktr_06
提出日時 2024-05-13 00:53:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,848 bytes
コンパイル時間 2,573 ms
コンパイル使用メモリ 207,996 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-05-13 00:53:26
合計ジャッジ時間 6,599 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
6,812 KB
testcase_01 AC 32 ms
6,944 KB
testcase_02 AC 32 ms
6,940 KB
testcase_03 AC 31 ms
6,940 KB
testcase_04 AC 31 ms
6,944 KB
testcase_05 AC 34 ms
6,944 KB
testcase_06 AC 34 ms
6,944 KB
testcase_07 AC 34 ms
6,940 KB
testcase_08 AC 34 ms
6,940 KB
testcase_09 AC 32 ms
6,940 KB
testcase_10 AC 31 ms
6,944 KB
testcase_11 AC 30 ms
6,944 KB
testcase_12 AC 32 ms
6,940 KB
testcase_13 AC 31 ms
6,944 KB
testcase_14 AC 31 ms
6,944 KB
testcase_15 AC 29 ms
6,944 KB
testcase_16 AC 30 ms
6,944 KB
testcase_17 AC 29 ms
6,944 KB
testcase_18 AC 29 ms
6,940 KB
testcase_19 AC 28 ms
6,940 KB
testcase_20 AC 20 ms
6,940 KB
testcase_21 AC 23 ms
7,296 KB
testcase_22 AC 17 ms
6,944 KB
testcase_23 AC 26 ms
6,940 KB
testcase_24 AC 24 ms
6,944 KB
testcase_25 AC 22 ms
6,940 KB
testcase_26 AC 18 ms
6,944 KB
testcase_27 AC 34 ms
7,552 KB
testcase_28 AC 28 ms
7,424 KB
testcase_29 AC 26 ms
7,040 KB
testcase_30 AC 26 ms
7,040 KB
testcase_31 AC 24 ms
7,424 KB
testcase_32 AC 29 ms
8,192 KB
testcase_33 AC 28 ms
8,192 KB
testcase_34 AC 28 ms
6,940 KB
testcase_35 AC 28 ms
7,680 KB
testcase_36 AC 24 ms
7,040 KB
testcase_37 AC 33 ms
7,552 KB
testcase_38 AC 23 ms
7,936 KB
testcase_39 AC 32 ms
7,808 KB
testcase_40 AC 33 ms
7,040 KB
testcase_41 AC 31 ms
7,680 KB
testcase_42 AC 26 ms
6,944 KB
testcase_43 AC 31 ms
8,448 KB
testcase_44 AC 26 ms
7,296 KB
testcase_45 AC 25 ms
7,808 KB
testcase_46 AC 27 ms
6,940 KB
testcase_47 AC 27 ms
6,944 KB
testcase_48 AC 29 ms
7,680 KB
testcase_49 AC 27 ms
7,936 KB
testcase_50 AC 32 ms
7,808 KB
testcase_51 AC 29 ms
7,168 KB
testcase_52 AC 30 ms
8,064 KB
testcase_53 AC 26 ms
6,944 KB
testcase_54 AC 35 ms
8,576 KB
testcase_55 AC 28 ms
7,680 KB
testcase_56 AC 31 ms
8,064 KB
testcase_57 AC 30 ms
7,552 KB
testcase_58 AC 26 ms
7,296 KB
testcase_59 AC 25 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const long long INF = 1LL << 60;

void solve(){
    int n, k;
    long long x;
    cin >> n >> k >> x;
    vector<long long> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }

    vector<vector<long long>> d(k);
    vector<long long> sum(k);
    for(int i = 0; i <= n; i++){
        if(i == 0 || i == n){
            d[i % k].push_back(INF);
        }else{
            d[i % k].push_back(h[i] - h[i - 1]);
            sum[i % k] += h[i] - h[i - 1];
        }
    }

    int m = h[0] % x;
    for(int i = 1; i < n; i++){
        if(h[i] % x != m){
            cout << "No" << "\n";
            return;
        }
    }

    for(int i = 0; i < k; i++){
        if(d[i][0] == INF && d[i].back() == INF){
            continue;
        }
        if(sum[i] != 0){
            if(d[i][0] == INF && (int) d[i].size() >= 2){
                if(sum[i] > 0){
                    d[i][1] += -sum[i];
                }else{
                    cout << "No" << "\n";
                    return;
                }
            }else if(d[i].back() == INF && (int) d[i].size() >= 2){
                if(sum[i] < 0){
                    d[i][d[i].size() - 2] += -sum[i];
                }else{
                    cout << "No" << "\n";
                    return;
                }
            }else{
                cout << "No" << "\n";
                return;
            }
        }
        long long cs = 0;
        for(auto v : d[i]){
            if(v == INF){
                continue;
            }
            cs += v;
            if(cs > 0){
                cout << "No" << "\n";
                return;
            }
        }
    }

    cout << "Yes" << "\n";
}

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

    int T; cin >> T;
    while(T--){
        solve();
    }
}
0