結果

問題 No.1594 Three Classes
ユーザー 4zuki4zuki
提出日時 2021-07-09 21:37:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 960 bytes
コンパイル時間 1,553 ms
コンパイル使用メモリ 167,728 KB
実行使用メモリ 14,768 KB
最終ジャッジ日時 2023-09-14 08:02:29
合計ジャッジ時間 8,141 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<int> e(n);
    int sum = 0;
    rep(i, n) {
        cin >> e[i];
        sum += e[i];
    }
    if (sum % 3 != 0) {
        cout << "No" << endl;
        return 0;
    }
    sum /= 3;
    vector<int> r(n);
    rep(i, n) r[i] = i;
    do {
        int pa = 0, pb = 0, pc = 0;
        int i = 0;
        while (pa < sum && i < n) {
            pa += e[r[i]];
            i++;
        }
        if (pa != sum) continue;
        while (pb < sum && i < n) {
            pb += e[r[i]];
            i++;
        }
        if (pb != sum) continue;
        while (pc < sum && i < n) {
            pc += e[r[i]];
            i++;
        }
        if (pc != sum) continue;
        cout << "Yes" << endl;
        return 0;
    } while (next_permutation(r.begin(), r.end()));
    cout << "No" << endl;
}
0