結果

問題 No.636 硬貨の枚数2
ユーザー しらっ亭
提出日時 2017-05-10 17:48:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 510 bytes
コンパイル時間 533 ms
コンパイル使用メモリ 62,276 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-09-19 10:23:36
合計ジャッジ時間 4,151 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 TLE * 1
other -- * 65
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <assert.h>

using namespace std;

int count(long long x) {
  int ret = 0;
  while (x) {
    ret += x % 5;
    if (x % 10 >= 5) ret++;
    x /= 10;
  }
  return ret;
}

int solve_naive(long long n) {
  int ans = 1e9;
  for (int x = n; x <= n * 3; x++) {
    int cand = count(x) + count(x-n);
    if (cand < ans) {
      ans = cand;
    }
  }
  return ans;
}

int main() {
  long long n;
  cin >> n;
  cout << solve_naive(n) << endl;
  return 0;
}
0