結果

問題 No.4 おもりと天秤
ユーザー rhincodon66rhincodon66
提出日時 2019-06-08 19:15:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 747 bytes
コンパイル時間 1,889 ms
コンパイル使用メモリ 170,880 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 19:59:32
合計ジャッジ時間 2,241 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};



int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> w(n);
	rep(i,n) cin >> w.at(i);
	int sum=0;
	rep(i,n) sum+=w.at(i);
	vector<vector<bool>> dp(n+1,vector<bool>(sum+1));
	dp[0][0]=true;
	rep(i,n){
		rep(j,sum){
			if(dp[i][j]){
				dp[i+1][j]=true;
				dp[i+1][j+w.at(i)]=true;
			}
		}
	}
	bool ans=false;
	rep(i,n+1) if(dp[i][sum/2]) ans=true;
	if(ans && sum%2==0) cout << "possible" << endl;
	else cout << "impossible" << endl;
}
0