結果

問題 No.1594 Three Classes
ユーザー h2929h2929
提出日時 2021-07-09 21:39:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 693 bytes
コンパイル時間 1,344 ms
コンパイル使用メモリ 169,052 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 00:05:04
合計ジャッジ時間 2,226 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long int
#define INF 1000000000000000000
using namespace std;

int main(void){
  ll n;
  cin >> n;
  vector<ll> e(n);
  for (int i = 0; i < n; i++){
    cin >> e[i];
  }

  bool ok = 0;
  vector<ll> tri(n, 0);
  auto dfs = [&](auto &dfs, int k){
    if (k == n){
      vector<ll> a(3, 0);
      for (ll i = 0; i < n; i++){
        a[tri[i]] += e[i];
      }
      if (a[0] == a[1] && a[1] == a[2])
        ok = 1;
      return;
    }

    tri[k] = 0;
    dfs(dfs, k+1);
    tri[k] = 1;
    dfs(dfs, k+1);
    tri[k] = 2;
    dfs(dfs, k+1);
  };

  dfs(dfs, 0);
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  

  return 0;
}
0