結果
問題 |
No.636 硬貨の枚数2
|
ユーザー |
|
提出日時 | 2021-09-24 14:22:28 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 604 bytes |
コンパイル時間 | 612 ms |
コンパイル使用メモリ | 68,736 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 09:42:22 |
合計ジャッジ時間 | 2,195 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 65 |
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 7 | main() | ^~~~
ソースコード
#include<iostream> #include<algorithm> using namespace std; string N; int dp[10101][2]; int cost[10]={0,1,2,3,4,1,2,3,4,5}; main() { cin>>N; N="0"+N; for(int i=0;i<=N.size();i++)dp[i][0]=dp[i][1]=1e9; dp[N.size()][0]=0; for(int i=N.size();i--;) { int n=N[i]-'0'; for(int j=0;j<2;j++) { for(int k=0;k<10;k++) { if (k!=0 && k!=5 && k!=n+j && k!=n+j+5 && k!=n+j-5) continue; if(n+j<=k) { dp[i][0]=min(dp[i][0],dp[i+1][j]+cost[k]+cost[k-n-j]); } else { dp[i][1]=min(dp[i][1],dp[i+1][j]+cost[k]+cost[10+k-n-j]); } } } } cout<<dp[0][0]<<endl; }