結果

問題 No.1594 Three Classes
ユーザー TsukumowanTsukumowan
提出日時 2021-07-10 13:52:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 929 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 202,476 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 00:37:51
合計ジャッジ時間 3,570 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 7 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 90 ms
6,940 KB
testcase_06 AC 7 ms
6,940 KB
testcase_07 AC 14 ms
6,944 KB
testcase_08 AC 89 ms
6,940 KB
testcase_09 AC 90 ms
6,940 KB
testcase_10 AC 89 ms
6,940 KB
testcase_11 AC 89 ms
6,940 KB
testcase_12 AC 89 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 56 ms
6,944 KB
testcase_15 AC 31 ms
6,944 KB
testcase_16 AC 16 ms
6,944 KB
testcase_17 AC 11 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 4 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int power(int p){
    int res = 1;
    for(int i = 0;i < p;i++) res *= 3;
    return res;
}

int main(){
    int n;
    cin >> n;
    vector<int64_t> v(n);
    int64_t sum = 0;
    for(int i = 0;i < n;i++){
        cin >> v[i];
        sum += v[i];
    }
    bool ans = false;
    if(sum % 3 == 0){
        for(int i = 0;i < power(n);i++){
            int64_t a = 0;
            int64_t b = 0;
            int64_t c = 0;
            int bi = i;
            for(int j = n;j > 0;j--){
                int rem = bi / power(j);
                if(rem == 0) a += v[j - 1];
                else if(rem == 1) b += v[j - 1];
                else c += v[j - 1];
                bi %= power(j);
            }
            if(a == b && b == c){
                ans = true;
                break;
            }
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}
0