結果

問題 No.1594 Three Classes
ユーザー bokusunnybokusunny
提出日時 2021-07-09 21:52:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 723 bytes
コンパイル時間 1,465 ms
コンパイル使用メモリ 165,656 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-10 06:50:22
合計ジャッジ時間 3,151 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

template <class T>
T my_pow(T a, T n) {
  assert(n >= 0);
  T res = 1;
  while (n > 0) {
    if (n & 1) res = res * a;
    a = a * a;
    n >>= 1;
  }
  return res;
}

int main() {
  int N;
  cin >> N;
  vector<int> E(N);
  for (int i = 0; i < N; i++) cin >> E[i];

  for (int i = 0; i < my_pow(3, N); i++) {
    int a = 0, b = 0, c = 0;
    for (int j = 0; j < N; j++) {
      int pow = my_pow(3, j);
      int flag = i / pow % 3;
      if (flag == 0)
        a += E[j];
      else if (flag == 1)
        b += E[j];
      else
        c += E[j];
    }
    if (a == b && b == c) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}
0