結果

問題 No.4 おもりと天秤
ユーザー ciel
提出日時 2014-11-16 00:04:20
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 370 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 36,224 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 09:04:03
合計ジャッジ時間 1,087 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%d",&n);
      |         ~~~~~^~~~~~~~~
main.cpp:9:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         for(int i=0;i<n;i++)scanf("%d",&v[i]),s+=v[i];
      |                             ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include <vector>
#include <cstdio>
using namespace std;

int main(){
	int n,s=0;
	scanf("%d",&n);
	vector<int>v(n);
	for(int i=0;i<n;i++)scanf("%d",&v[i]),s+=v[i];
	if(s%2){
		puts("impossible");
		return 0;
	}
	vector<int>bag(s+1);
	bag[0]=1;
	for(int i=0;i<n;i++)for(int j=s;j>=v[i];j--)bag[j]|=bag[j-v[i]];
	puts(bag[s/2]?"possible":"impossible");
}
0