結果

問題 No.10 +か×か
ユーザー akakimidoriakakimidori
提出日時 2016-12-11 23:42:54
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 796 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 25,232 KB
実行使用メモリ 20,232 KB
最終ジャッジ日時 2023-08-21 06:21:06
合計ジャッジ時間 1,006 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,380 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 10 ms
18,452 KB
testcase_04 AC 6 ms
12,200 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 9 ms
20,232 KB
testcase_07 AC 6 ms
12,328 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 4 ms
6,128 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 0 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define POS(i,j) ((i)*(total+1)+(j))

void run(void){
  int n,total;
  scanf("%d%d",&n,&total);
  int *A=(int *)malloc(sizeof(int)*(n+1));
  int i;
  for(i=1;i<=n;i++){
    scanf("%d",A+i);
  }

  int *dp=(int *)calloc((total+1)*(n+1),sizeof(int));
  dp[POS(n,total)]=1;
  for(i=n;i>=2;i--){
    int k;
    for(k=total;k>=0;k--){
      if(dp[POS(i,k)]){
        if(k-A[i]>=0){
          dp[POS(i-1,k-A[i])]=1;
        }
        if(k%A[i]==0){
          dp[POS(i-1,k/A[i])]=1;
        }
      }
    }
  }

  int now=A[1];
  for(i=2;i<=n;i++){
    int t=now+A[i];
    if(t<=total && dp[POS(i,t)]){
      printf("+");
      now=t;
    } else {
      printf("*");
      now=now*A[i];
    }
  }
  printf("\n");
  return;
}

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