結果

問題 No.332 数列をプレゼントに
ユーザー akakimidoriakakimidori
提出日時 2019-01-10 02:47:52
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 1,365 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 30,736 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-15 17:02:59
合計ジャッジ時間 8,352 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 74 ms
4,380 KB
testcase_08 RE -
testcase_09 AC 1 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 RE -
testcase_17 AC 2 ms
4,380 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 75 ms
4,380 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 RE -
testcase_28 WA -
testcase_29 WA -
testcase_30 RE -
testcase_31 WA -
testcase_32 AC 37 ms
4,380 KB
testcase_33 AC 5 ms
4,380 KB
testcase_34 AC 19 ms
4,380 KB
testcase_35 AC 75 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 3 ms
4,376 KB
testcase_45 AC 1,315 ms
4,380 KB
testcase_46 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

#define POS(i,j) ((i)*(100*blen+1)+(j))

void run(void){
  int n;
  int64 x;
  scanf("%d%lld",&n,&x);
  int a[100];
  int i,j;
  for(i=0;i<n;i++) scanf("%d",a+i);
  int b[100],c[10];
  int blen=0;
  int clen=0;
  for(i=0;i<n;i++){
    if(a[i]<=100){
      b[blen++]=i;
    } else {
      c[clen++]=i;
    }
  }
  char *dp=(char *)calloc((blen+1)*(100*blen+1),sizeof(char));
  dp[POS(0,0)]=1;
  for(i=0;i<blen;i++){
    memcpy(dp+POS(i+1,0),dp+POS(i,0),100*blen+1);
    int x=a[b[i]];
    for(j=100*blen;j>=x;j--){
      if(dp[POS(i,j-x)]){
	dp[POS(i+1,j)]=1;
      }
    }
  }
  for(i=0;i<(1<<clen);i++){
    int64 sum=0;
    for(j=0;j<clen;j++){
      if((i>>j)&1){
	sum+=a[c[j]];
      }
    }
    if(x-sum>=0 && x-sum<=100*blen && dp[POS(blen,(int)(x-sum))]){
      x-=sum;
      break;
    }
  }
  if(i>=(1<<clen)){
    printf("No\n");
    return;
  }
  char *ans=(char *)calloc(n+1,sizeof(char));
  for(j=0;j<clen;j++){
    ans[c[j]]=((i>>j)&1)?'o':'x';
  }
  int y=(int)x;
  for(i=blen-1;i>=0;i--){
    if(dp[POS(i,y-a[b[i]])]){
      ans[b[i]]='o';
      y-=a[b[i]];
    } else {
      ans[b[i]]='x';
    }
  }
  puts(ans);
}

int main(void){
  run();
  return 0;
}
0