結果
| 問題 | No.10 +か×か |
| コンテスト | |
| ユーザー |
TLwiegehtt
|
| 提出日時 | 2015-07-14 07:52:45 |
| 言語 | C90 (gcc 12.4.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 5,000 ms |
| コード長 | 667 bytes |
| 記録 | |
| コンパイル時間 | 511 ms |
| コンパイル使用メモリ | 37,476 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-12-06 14:31:53 |
| 合計ジャッジ時間 | 1,208 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 |
ソースコード
#include <stdio.h>
char dp[55][100100];
int main(void){
int p;
int i,j,n,total;
int a[55];
scanf("%d", &n);
scanf("%d", &total);
for(i=0;i<n;i++){
scanf("%d", &a[i]);
}
dp[n][total] = 1;
for(i=n-1;i>=0;i--){
for(j=0;j<total+1;j++){
int tmp = j+a[i];
dp[i][j] = 0;
if( tmp <= total && dp[i+1][tmp]){
dp[i][j] = 1;
}
tmp = j*a[i];
if( tmp <= total && dp[i+1][tmp]){
dp[i][j] = 1;
}
}
}
p = a[0];
for(i=1;i<n;i++){
if( (p+a[i]) <= total && dp[i+1][p+a[i]] ){ p+=a[i]; printf("+"); continue; }
if( (p*a[i]) <= total && dp[i+1][p*a[i]] ){ p*=a[i]; printf("*"); continue; }
}
printf("\n");
return 0;
}
TLwiegehtt