結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
Humpty0904
|
| 提出日時 | 2016-06-15 04:49:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 353 bytes |
| コンパイル時間 | 279 ms |
| コンパイル使用メモリ | 36,352 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-26 09:34:40 |
| 合計ジャッジ時間 | 1,218 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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];
| ~~~~~^~~~~~~~~~~~
ソースコード
#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");
}
Humpty0904