結果

問題 No.4 おもりと天秤
ユーザー hitoyozakehitoyozake
提出日時 2018-05-15 20:41:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 992 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 77,208 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 21:05:47
合計ジャッジ時間 1,816 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>

int main()
{
    int n = 0;
    std::cin >> n;

    bool found = false;

    std::vector< int > v;

    for( int i = 0; i < n; ++i )
       {
           int tmp;
           std::cin >> tmp;
           v.push_back(tmp);
       }

    std::sort(v.begin(), v.end());

    int sum = std::accumulate(v.begin(), v.end(), 0);
    int h = sum/2;

    if(sum % 2 == 0)
    for( auto it = v.rbegin(); it != v.rend(); ++it )
    {
        //std::cout << "it: " << *it << std::endl;
        if(sum - *it >= h )
        {
            sum -= *it;
        }
        else
        {
            sum -= *it;
            h -= *it;
        }
        //std::cout << "sum: " << sum << ", half:" << h << std::endl;
    }


    if( sum == 0 && h == 0 )
        found = true;
    
    if( found )
        std::cout << "possible" << std::endl;
    else
        std::cout << "impossible" << std::endl;

}
0