結果

問題 No.1594 Three Classes
ユーザー sk461
提出日時 2021-07-09 23:50:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 841 bytes
コンパイル時間 953 ms
コンパイル使用メモリ 70,784 KB
最終ジャッジ日時 2025-01-22 22:56:43
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
int n;
vector<int> e(20);
vector<int> v(20, 0);
bool fg = 0;
void dfs(int cnt) {
    if (cnt == n) {
        int cnt1 = 0, cnt2 = 0, cnt3 = 0;
        for (int i = 0; i < n; i++) {
            if (v[i] == 0) {
                cnt1 += e[i];
            } else if (v[i] == 1) {
                cnt2 += e[i];
            } else {
                cnt3 += e[i];
            }
        }
        if (cnt1 == cnt2 && cnt2 == cnt3) {
            fg = 1;
        }
        return;
    }
    for (int i = 0; i < 3; i++) {
        v[cnt] = i;
        dfs(cnt + 1);
    }
    return;
}
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> e[i];
    }
    dfs(0);
    if (fg) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}
0