結果

問題 No.4 おもりと天秤
ユーザー KotRm
提出日時 2019-03-15 22:10:27
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 769 bytes
コンパイル時間 556 ms
コンパイル使用メモリ 55,516 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-01 21:01:48
合計ジャッジ時間 1,441 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define print(x) cout << x << endl;
using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, W;
    cin >> N;
    
    /*dp[i][w]: i番目までのおもりを利用して(片側が)総重量wとなる分け方が存在するか*/
    int sum=0;
    bool dp[101][10101];
    dp[0][0] = true;
    
    string ans = "impossible";
    REP(i, N){
        cin >> W;
        sum += W;
        REP(j, 10101){
            if(dp[i][j] == true){
                dp[i + 1][j + W] = true;
                dp[i + 1][j] = true;
            }
        }
    }
    
    if(sum%2==0 && dp[N][sum/2]){
        ans = "possible";
    }
    print(ans);
}
0