結果
問題 |
No.10 +か×か
|
ユーザー |
![]() |
提出日時 | 2014-12-03 02:11:12 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 817 bytes |
コンパイル時間 | 233 ms |
コンパイル使用メモリ | 34,656 KB |
実行使用メモリ | 10,240 KB |
最終ジャッジ日時 | 2024-06-11 07:57:28 |
合計ジャッジ時間 | 6,805 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 WA * 1 TLE * 1 -- * 7 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:23:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 23 | scanf("%d%d", &N, &T); | ~~~~~^~~~~~~~~~~~~~~~ main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | scanf("%d", a+i); | ~~~~~^~~~~~~~~~~
ソースコード
#include <cstdio> #include <algorithm> using namespace std; int N, T; int a[50]; char dp[51][100001]; bool dfs(int m, int t){ if(m == 0) return t == a[m]; if(t > a[m] && dfs(m - 1, t - a[m])){ putchar('+'); return true; } if(t && t % a[m] == 0 && 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]; } } dfs(N-1, T); puts(""); return 0; }