結果

問題 No.2643 Many Range Sums Problems
ユーザー RubikunRubikun
提出日時 2024-02-19 22:13:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 202 ms / 8,000 ms
コード長 2,012 bytes
コンパイル時間 2,091 ms
コンパイル使用メモリ 206,648 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-19 22:13:26
合計ジャッジ時間 4,967 ms
ジャッジサーバーID
(参考情報)
judge16 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 140 ms
6,676 KB
testcase_04 AC 98 ms
6,676 KB
testcase_05 AC 57 ms
6,676 KB
testcase_06 AC 187 ms
6,676 KB
testcase_07 AC 191 ms
6,676 KB
testcase_08 AC 54 ms
6,676 KB
testcase_09 AC 37 ms
6,676 KB
testcase_10 AC 157 ms
6,676 KB
testcase_11 AC 61 ms
6,676 KB
testcase_12 AC 23 ms
6,676 KB
testcase_13 AC 30 ms
6,676 KB
testcase_14 AC 159 ms
6,676 KB
testcase_15 AC 168 ms
6,676 KB
testcase_16 AC 51 ms
6,676 KB
testcase_17 AC 59 ms
6,676 KB
testcase_18 AC 10 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 11 ms
6,676 KB
testcase_21 AC 4 ms
6,676 KB
testcase_22 AC 9 ms
6,676 KB
testcase_23 AC 12 ms
6,676 KB
testcase_24 AC 20 ms
6,676 KB
testcase_25 AC 21 ms
6,676 KB
testcase_26 AC 3 ms
6,676 KB
testcase_27 AC 3 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 202 ms
6,676 KB
testcase_31 AC 93 ms
6,676 KB
testcase_32 AC 22 ms
6,676 KB
testcase_33 AC 22 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,K;cin>>N>>K;
    vector<ll> R(N),X(N);
    for(int i=0;i<N;i++) cin>>R[i]>>X[i];
    
    for(ll ng=0;ng<N;ng++){
        bool ok=true;
        vector<ll> S(N+1);
        for(ll i=N-1;i>ng;i--){
            S[i]=S[R[i]]+X[i];
            ll diff=S[i]-S[i+1];
            ok&=(0<=diff&&diff<=K);
        }
        if(!ok){
            cout<<"No\n";
            continue;
        }
        
        vector<ll> A=S,B=S,C=S;
        A[ng]=A[ng+1]+0;
        B[ng]=B[ng+1]+1;
        C[ng]=C[ng+1]+2;
        
        ll left=0,right=K;
        
        for(ll i=ng-1;i>=0;i--){
            A[i]=A[R[i]]+X[i];
            B[i]=B[R[i]]+X[i];
            C[i]=C[R[i]]+X[i];
            
            ll a=A[i]-A[i+1],b=B[i]-B[i+1],c=C[i]-C[i+1];
            if(a==b&&b==c){
                if(0<=a&&a<=K){
                    
                }else{
                    left=0;
                    right=-1;
                    break;
                }
            }else{
                assert(abs(a-b)==1);
                
                if(a<b){
                    ll L=-a,R=K-a;
                    chmax(left,L);
                    chmin(right,R);
                }else{
                    ll L=a-K,R=a;
                    chmax(left,L);
                    chmin(right,R);
                }
            }
        }
        
        if(left<=right){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
    }
}

0