結果

問題 No.1594 Three Classes
ユーザー bokusunny
提出日時 2021-07-09 21:52:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 723 bytes
コンパイル時間 1,533 ms
コンパイル使用メモリ 168,068 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-16 07:40:52
合計ジャッジ時間 3,116 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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