結果

問題 No.4 おもりと天秤
ユーザー syutaro
提出日時 2017-06-24 00:59:12
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 927 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 74,648 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-03 04:08:48
合計ジャッジ時間 1,568 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 5
権限があれば一括ダウンロードができます

ソースコード

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(i + itr->first ==  sum / 2) {
                cout << "possible" << endl;
                return 0;
            }
            mm[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