結果

問題 No.4 おもりと天秤
ユーザー sugarrrsugarrr
提出日時 2018-01-04 14:14:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 599 bytes
コンパイル時間 472 ms
コンパイル使用メモリ 67,588 KB
実行使用メモリ 5,716 KB
最終ジャッジ日時 2023-09-08 17:38:04
合計ジャッジ時間 1,464 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #



#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
typedef long long ll;
using namespace std;

int main(){
    int n;cin>>n;
    int w[n+1];for(int i=1;i<=n;i++)cin>>w[i];
    bool dp[n+1][22001];
    for(int i=0;i<=22000;i++)dp[0][i]=false;
    dp[0][11000]=true;
    for(int i=1;i<=n;i++)for(int j=0;j<=22000;j++){
        dp[i][j]=(dp[i-1][j+w[i]]||dp[i-1][j-w[i]]);
    }
   if(dp[n][11000]==true)printf("possible");
    else printf("impossible");
    return 0;
}

0