結果

問題 No.1594 Three Classes
ユーザー simkarensimkaren
提出日時 2021-11-15 11:08:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 892 bytes
コンパイル時間 2,026 ms
コンパイル使用メモリ 179,220 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-10 07:08:07
合計ジャッジ時間 3,368 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int ipow(int a, int b){
    if (b == 0) return 1;
    int tmp = ipow(a, b / 2);
    tmp = tmp * tmp;
    if (b % 2 == 0) return tmp;
    return tmp * a;
}

int N;
vector<int> E;

void input(void){
    cin >> N;
    E.resize(N);
    for (int& ei : E)
        cin >> ei;
}

bool _judge(int flg){
    int pa = 0, pb = 0, pc = 0;
    for (int i = 0; i < N; ++i){
        if (flg % 3 == 0) pa += E[i];
        else if (flg % 3 == 1) pb += E[i];
        else pc += E[i];
        flg /= 3;
    }
    return (pa == pb && pb == pc);
}

bool judge(void){
    int upper_flg = ipow(3, N);
    for (int flg = 0; flg < upper_flg; ++flg)
        if (_judge(flg)) return true;
    return false;
}

int main(void){
    input();
    if (judge()) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
0