結果

問題 No.4 おもりと天秤
ユーザー syutarosyutaro
提出日時 2017-06-24 01:44:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 933 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 74,612 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 17:31:24
合計ジャッジ時間 2,038 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <set>
#define rep(i, n) for(int (i)=0; (i)<(n); ++(i))
using namespace std;

int main()
{
    int n;
    cin >> n;
    int w[100];
    map<int, bool> m;
    m[0] = true;
    int sum = 0;
    rep(i, n) {
        cin >> w[i];
        sum += w[i];
    }
    if(sum % 2 ==  1) {
        cout << "impossible" << endl;
	    return 0;
    }

    rep(i, n) {
        map<int, bool> mm;
        for(map<int, bool>::iterator itr = m.begin(); itr != m.end(); ++itr) {
            if(w[i] + itr->first ==  sum / 2) {
                cout << "possible" << endl;
                return 0;
            }
            mm[w[i] + itr->first] = true;
        }

        for(map<int, bool>::iterator itr = mm.begin(); itr != mm.end(); ++itr) {
            m[itr->first] = true;
        }
    }

    cout << "impossible" << endl;
	return 0;
}
0