結果

問題 No.634 硬貨の枚数1
コンテスト
ユーザー 梧桐
提出日時 2025-11-18 03:11:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 639 bytes
コンパイル時間 689 ms
コンパイル使用メモリ 63,152 KB
実行使用メモリ 43,776 KB
最終ジャッジ日時 2025-11-18 03:12:08
合計ジャッジ時間 15,145 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 75
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 4510, M = 10200000;

int n, a[N], b[M], cnt, idx;

int main() {
    for (int i = 1; i < N; ++i) {
        a[i] = i * (i + 1) / 2;
    }
    for (int i = 1; i < M; ++i) b[i] = 3;
    for (int i = 1; i < N; ++i) {
        for (int j = i; j < N; ++j) {
            if (a[i] + a[j] >= M) break;
            b[a[i] + a[j]] = 2;
        }
    }
    for (int i = 1; i < N; ++i) b[a[i]] = 1;
    scanf("%d", &n);
    cnt = b[n];
    for (int i = 1; i < N && n - a[i] >= 1; ++i) {
        cnt = min(cnt, b[n - a[i]] + 1);
    }
    printf("%d\n", cnt);

    return 0;
}
0