結果

問題 No.4 おもりと天秤
ユーザー pessimist
提出日時 2025-06-07 17:25:52
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 518 bytes
コンパイル時間 625 ms
コンパイル使用メモリ 27,472 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-07 17:25:54
合計ジャッジ時間 1,732 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:5:13: warning: multi-character character constant [-Wmultichar]
    5 | _Bool check['-~'];
      |             ^~~~
main.c: In function ‘main’:
main.c:13:3: warning: implicit declaration of function ‘qsort’ [-Wimplicit-function-declaration]
   13 |   qsort(w,n,sizeof(int),cmp);
      |   ^~~~~
main.c:8:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |   scanf("%d",&n);
      |   ^~~~~~~~~~~~~~
main.c:10:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |     scanf("%d",&w[i]);
      |     ^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
int cmp(const void* a, const void* b){
  return *(int*)a - *(int*)b;
}
_Bool check['-~'];
int main(){
  int i,j,n,w['~'],s=0;
  scanf("%d",&n);
  for(int 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(int i=0;i<n;++i){
      for(int j=s-w[i];j>=0;--j){
        if(check[j]) check[j+w[i]]=1;
      }
    }
    if(check[s]) printf("possible\n");
    else printf("impossible\n");
  } 
  else printf("impossible\n");
}
0