結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-26 15:37:34 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 476 bytes |
| コンパイル時間 | 155 ms |
| コンパイル使用メモリ | 21,504 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-26 10:05:53 |
| 合計ジャッジ時間 | 815 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:13:9: warning: implicit declaration of function ‘qsort’ [-Wimplicit-function-declaration]
13 | qsort(w,n,sizeof(int),cmp);
| ^~~~~
main.c:8:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | scanf("%d",&n);
| ^~~~~~~~~~~~~~
main.c:10:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d",&w[i]);
| ^~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
int cmp(const void*a,const void*b){
return *(int*)b-*(int*)a;
}
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=s-w[i];j>=0;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;
}