結果
| 問題 |
No.10 +か×か
|
| コンテスト | |
| ユーザー |
Irmystp
|
| 提出日時 | 2014-12-03 02:22:15 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 901 bytes |
| コンパイル時間 | 411 ms |
| コンパイル使用メモリ | 35,168 KB |
| 実行使用メモリ | 6,528 KB |
| 最終ジャッジ日時 | 2024-06-11 07:59:48 |
| 合計ジャッジ時間 | 970 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 5 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
24 | scanf("%d%d", &N, &T);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:26:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
26 | scanf("%d", a+i);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <cstdio>
#include <algorithm>
#include <cassert>
using namespace std;
int N, T;
int a[50];
char dp[51][100001];
bool dfs(int m, int t){
if(m == 0) return true;
if(t > a[m] && dp[m - 1][t - a[m]] && dfs(m - 1, t - a[m])){
putchar('+');
return true;
}
if(t % a[m] == 0 && dp[m - 1][t / a[m]] && dfs(m - 1, t / a[m])){
putchar('*');
return true;
}
return false;
}
int main(){
scanf("%d%d", &N, &T);
for(int i = 0; i < N; i++){
scanf("%d", a+i);
fill(dp[i], dp[i]+T+1, 0);
}
dp[0][a[0]] = 1;
for(int i = 1; i < N; i++){
for(int j = 1; j <= T; j++){
if(j*a[i] <= T) dp[i][j*a[i]] |= dp[i-1][j];
if(j+a[i] <= T) dp[i][j+a[i]] |= dp[i-1][j];
}
}
assert(dp[N-1][T]!=0);
dfs(N-1, T);
puts("");
return 0;
}
Irmystp