結果
問題 |
No.636 硬貨の枚数2
|
ユーザー |
![]() |
提出日時 | 2018-01-19 23:14:10 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 1,056 bytes |
コンパイル時間 | 1,590 ms |
コンパイル使用メモリ | 160,496 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-24 12:52:01 |
合計ジャッジ時間 | 3,181 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 65 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; #define fi first #define se second #define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++) #define rep(i,n) repl(i,0,n) #define all(x) (x).begin(),(x).end() #define dbg(x) cout<<#x"="<<x<<endl #define mmax(x,y) (x>y?x:y) #define mmin(x,y) (x<y?x:y) #define maxch(x,y) x=mmax(x,y) #define minch(x,y) x=mmin(x,y) #define uni(x) x.erase(unique(all(x)),x.end()) #define exist(x,y) (find(all(x),y)!=x.end()) #define bcnt __builtin_popcount #define INF 1e16 ll n; string s; ll dp[10011][10]; ll calc(ll m){ return min((m+4)/5+(((m+4)/5)*5-m),m/5+m%5); } int main(){ cin>>s; s="0"+s; n=s.size(); rep(i,10011)rep(j,10)dp[i][j]=INF; dp[0][0]=0; rep(i,n)rep(j,10){ if(dp[i][j]==INF)continue; rep(k,10){ ll r=j*10-(s[i]-'0')-k; if(r>0){ minch(dp[i+1][k],dp[i][j]+calc(r)); }else{ r=-r; minch(dp[i+1][k],dp[i][j]+calc(r)); } } } cout<<dp[n][0]<<endl; return 0; }