結果

問題 No.1594 Three Classes
ユーザー Nzt3
提出日時 2022-10-12 01:40:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 573 bytes
コンパイル時間 1,978 ms
コンパイル使用メモリ 198,284 KB
最終ジャッジ日時 2025-02-08 01:40:49
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin>>N;
  vector<int>A(N);
  for(int &i:A)cin>>i;
  stack<array<int,2>>dfs;
  array<int,4>cnt={0,0,0,0};
  dfs.push({0,0});
  bool ans=false;
  while(dfs.size()){
    int v=dfs.top()[0],c=dfs.top()[1];
    dfs.pop();
    cnt[c]-=A[v];
    if(c<3){
      cnt[c+1]+=A[v];
      dfs.push({v,c+1});
      if(v+1<N){
        dfs.push({v+1,0});
      }else{
        if(cnt[1]==cnt[2]&&cnt[2]==cnt[3])ans=true;
      }
    }
  }
  cout<<(ans?"Yes\n":"No\n");
}
0