結果

問題 No.1594 Three Classes
ユーザー bokusunnybokusunny
提出日時 2021-07-09 21:52:11
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 723 bytes
コンパイル時間 1,440 ms
使用メモリ 3,540 KB
最終ジャッジ日時 2022-12-17 02:00:02
合計ジャッジ時間 3,569 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 95 ms
3,428 KB
testcase_01 AC 2 ms
3,532 KB
testcase_02 AC 2 ms
3,528 KB
testcase_03 AC 4 ms
3,480 KB
testcase_04 AC 97 ms
3,476 KB
testcase_05 AC 96 ms
3,452 KB
testcase_06 AC 3 ms
3,500 KB
testcase_07 AC 6 ms
3,444 KB
testcase_08 AC 95 ms
3,536 KB
testcase_09 AC 96 ms
3,504 KB
testcase_10 AC 95 ms
3,444 KB
testcase_11 AC 96 ms
3,524 KB
testcase_12 AC 96 ms
3,444 KB
testcase_13 AC 2 ms
3,540 KB
testcase_14 AC 21 ms
3,540 KB
testcase_15 AC 12 ms
3,372 KB
testcase_16 AC 7 ms
3,524 KB
testcase_17 AC 5 ms
3,428 KB
testcase_18 AC 1 ms
3,376 KB
testcase_19 AC 2 ms
3,536 KB
testcase_20 AC 2 ms
3,484 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