結果
問題 | No.10 +か×か |
ユーザー |
![]() |
提出日時 | 2014-11-16 04:21:47 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 45 ms / 5,000 ms |
コード長 | 1,160 bytes |
コンパイル時間 | 424 ms |
コンパイル使用メモリ | 56,724 KB |
実行使用メモリ | 47,488 KB |
最終ジャッジ日時 | 2024-12-14 15:25:40 |
合計ジャッジ時間 | 1,380 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 12 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:11:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | scanf("%d %d", &N, &total); | ~~~~~^~~~~~~~~~~~~~~~~~~~~ main.cpp:13:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 13 | for(int i=0;i<N;i++){scanf("%d", A+i);} | ~~~~~^~~~~~~~~~~
ソースコード
#include<cstdio> #include<iostream> const long long INF = 1001001001001001001; int N, total, A[50]; bool can[50][100001]; long long ope[50][100001]; int main(){ scanf("%d %d", &N, &total); for(int i=0;i<N;i++){scanf("%d", A+i);} std::fill(&can[0][0], &can[0][0]+50*100001, false); std::fill(&ope[0][0], &ope[0][0]+50*100001, INF); can[0][A[0]] = true; ope[0][A[0]] = 0ll; for(int i=1;i<N;i++){ for(int j=0;j<=total;j++){ if(j - A[i] >= 0 && can[i-1][j-A[i]]){ can[i][j] = true; ope[i][j] = std::min(ope[i][j], ope[i-1][j-A[i]] << 1); } if(j % A[i] == 0 && can[i-1][j/A[i]]){ can[i][j] = true; ope[i][j] = std::min(ope[i][j], (ope[i-1][j/A[i]] << 1) + 1ll); } } } // for(int i=0;i<N;i++){ // for(int j=0;j<=total;j++){ // printf("%d ", can[i][j]); // } // puts(""); // } for(int i=N-2;i>=0;i--){ if(ope[N-1][total] >> i & 1){putchar('*');} else{putchar('+');} } puts(""); }