結果

問題 No.634 硬貨の枚数1
ユーザー しらっ亭
提出日時 2017-05-10 16:20:37
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 431 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 62,660 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-25 18:19:11
合計ジャッジ時間 2,441 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9 WA * 66
権限があれば一括ダウンロードができます

ソースコード

diff #

// 想定WA解法(貪欲)
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int solve(int n) {

  vector<int> T;
  for (int t, i = 1; (t = i * (i + 1) / 2) <= n; i++) {
    T.emplace_back(t);
  }

  int ans = 0;

  while (n) {
    int t = T.back(); T.pop_back();
    int d = n / t;
    n -= d * t;
    ans += d;
  }

  return ans;
}

int main() {
  int n;
  cin >> n;
  cout << solve(n) << endl;
}

0