結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-26 15:32:01 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 477 bytes |
| コンパイル時間 | 464 ms |
| コンパイル使用メモリ | 21,120 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-15 00:07:57 |
| 合計ジャッジ時間 | 1,366 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 WA * 3 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:14:9: warning: implicit declaration of function ‘qsort’ [-Wimplicit-function-declaration]
14 | qsort(w,n,sizeof(int),cmp);
| ^~~~~
main.c:9:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | scanf("%d",&n);
| ^~~~~~~~~~~~~~
main.c:11:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | scanf("%d",&w[i]);
| ^~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
int cmp(const void*a,const void*b){
return *(int*)a-*(int*)b;
}
int check[5001];
int main(){
int i,j,n,w[128],s=0;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&w[i]);
s+=w[i];
}
qsort(w,n,sizeof(int),cmp);
if(s%2==0){
s/=2;
check[0]=1;
for(i=0;i<n;i++){
for(j=0;j+w[i]<=s;j++){
if(check[j]==1) check[j+w[i]]=1;
}
}
if(check[s]) printf("possible\n");
else printf("impossible\n");
}else printf("impossible\n");
return 0;
}