結果
| 問題 |
No.636 硬貨の枚数2
|
| コンテスト | |
| ユーザー |
akun0716
|
| 提出日時 | 2020-05-03 16:17:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,684 bytes |
| コンパイル時間 | 976 ms |
| コンパイル使用メモリ | 84,060 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-12 21:01:10 |
| 合計ジャッジ時間 | 2,937 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 3 |
| other | AC * 15 WA * 50 |
ソースコード
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int dp[1000010][2];
string S;
cin >> S;
reverse(S.begin(), S.end());
S += '0';
int N = S.size();
REP(i, N + 1)REP(j, 2)dp[i][j] = INF;
dp[0][0] = 0;
REP(i, N) {
REP(j, 2) {
int x = S[i] - '0';
x += j;
REP(a, 10) {
int ni = i + 1, nj = 0;
int b = a - x;
if (b < 0) {
nj = 1;
b += 10;
}
chmin(dp[ni][nj], dp[i][j] + a + b);
}
}
}
cout << dp[N][0] << endl;
return 0;
}
akun0716