結果

問題 No.1823 Tricolor Dango
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-24 22:49:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 979 bytes
コンパイル時間 1,005 ms
コンパイル使用メモリ 111,664 KB
実行使用メモリ 12,764 KB
最終ジャッジ日時 2023-08-25 14:25:23
合計ジャッジ時間 5,977 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 42 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 46 ms
4,380 KB
testcase_14 AC 45 ms
4,376 KB
testcase_15 AC 40 ms
4,380 KB
testcase_16 AC 19 ms
5,544 KB
testcase_17 AC 31 ms
5,072 KB
testcase_18 AC 69 ms
7,580 KB
testcase_19 AC 212 ms
12,764 KB
testcase_20 AC 73 ms
7,672 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

void solve(){

    ll N, S=0, A, a, b, c;
    cin >> N;
    multiset<ll> st;;
    for (int i=0; i<N; i++){
        cin >> A;
        S += A;
        st.insert(A);
    }

    if (S % 3 != 0){
        cout << "No" << endl;
        return;
    }

    while(st.size() >= 3){
        a = *st.rbegin();
        st.erase(prev(st.end()));
        b = *st.rbegin();
        st.erase(prev(st.end()));
        c = *st.rbegin();
        st.erase(prev(st.end()));
        b -= c;
        if (b > 0) st.insert(b);
        a -= c;
        if (a > 0) st.insert(a);
    }

    cout << (st.size() == 0 ? "Yes" : "No") << endl;
}

int main(){

    int T;
    cin >> T;

    while(T){
        solve();
        T--;
    }

    return 0;
}
0