結果

問題 No.1594 Three Classes
ユーザー haruki_4936haruki_4936
提出日時 2022-02-12 22:03:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,559 bytes
コンパイル時間 4,445 ms
コンパイル使用メモリ 260,036 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-10 07:11:23
合計ジャッジ時間 5,885 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 37 ms
4,384 KB
testcase_04 AC 37 ms
4,376 KB
testcase_05 AC 37 ms
4,380 KB
testcase_06 AC 37 ms
4,376 KB
testcase_07 AC 36 ms
4,380 KB
testcase_08 AC 37 ms
4,380 KB
testcase_09 AC 37 ms
4,380 KB
testcase_10 AC 37 ms
4,380 KB
testcase_11 AC 37 ms
4,384 KB
testcase_12 AC 36 ms
4,376 KB
testcase_13 AC 2 ms
4,388 KB
testcase_14 AC 36 ms
4,380 KB
testcase_15 AC 37 ms
4,380 KB
testcase_16 AC 13 ms
4,376 KB
testcase_17 AC 37 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (long long i = 0; i < (n); i++)
#define rep1(i, n) for(long long i = 1; i <= (n); i++)
#define all(v) v.begin(),v.end()
#define decimal(n) cout << fixed << setprecision(n);
using namespace std; 
using namespace atcoder;
using ll = long long; using vl = vector<ll>; using P = pair<ll,ll>;
using vvl = vector<vl>; using vc = vector<char>; using vvc = vector<vc>;
using mint = modint998244353;
// using mint = modint1000000007;
const ll MOD = 998244353;
const ll MAX = 2000100; const ll inf = 3e18; const long double pi = acos(-1);
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
ll lcm(ll a,ll b){ return (a*b) / gcd(a,b); }

// DFSで長さnの0,1,2列を全て生成するコード
// 3^n 通りの全探索ができる
 
ll n;
vl v;
vl e;
bool flag;
 
void check(vl &v) {
    ll a = 0, b = 0, c = 0;
    rep(i, n){
      if(v[i] == 0) a += e[i];
      else if(v[i] == 1) b += e[i];
      else c += e[i];
    }

    if(a == b and b == c) flag = true;
}
 
void dfs(ll depth) {
    if(depth == n) {
        check(v);
        return;
    }
    rep(i,3){  // ここの数字を2からaに変更すると (a+1)^n 通りの全探索ができる
        v[depth] = i;
        dfs(depth + 1);
    }
}

int main(){
  cin >> n; v.resize(n); e.resize(n);
  rep(i, n) cin >> e[i];

  dfs(0);

  cout << ( flag ? "Yes" : "No") << endl; 
  
}
0