結果

問題 No.634 硬貨の枚数1
ユーザー tkmst201tkmst201
提出日時 2021-02-11 11:09:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 1,103 bytes
コンパイル時間 2,015 ms
コンパイル使用メモリ 201,980 KB
実行使用メモリ 42,328 KB
最終ジャッジ日時 2023-09-25 00:13:49
合計ジャッジ時間 17,298 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 18 ms
7,140 KB
testcase_15 AC 324 ms
36,416 KB
testcase_16 AC 90 ms
17,456 KB
testcase_17 AC 108 ms
20,976 KB
testcase_18 AC 67 ms
17,212 KB
testcase_19 AC 277 ms
32,668 KB
testcase_20 AC 327 ms
38,096 KB
testcase_21 AC 358 ms
40,424 KB
testcase_22 AC 318 ms
35,632 KB
testcase_23 AC 59 ms
15,856 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 10 ms
5,424 KB
testcase_35 AC 44 ms
13,840 KB
testcase_36 AC 175 ms
25,676 KB
testcase_37 AC 113 ms
18,456 KB
testcase_38 AC 16 ms
6,888 KB
testcase_39 AC 293 ms
34,556 KB
testcase_40 AC 166 ms
24,508 KB
testcase_41 AC 144 ms
22,760 KB
testcase_42 AC 284 ms
33,100 KB
testcase_43 AC 77 ms
15,624 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 16 ms
7,080 KB
testcase_47 AC 380 ms
42,276 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 16 ms
6,932 KB
testcase_50 AC 389 ms
42,328 KB
testcase_51 AC 16 ms
6,876 KB
testcase_52 AC 1 ms
4,376 KB
testcase_53 AC 1 ms
4,376 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 384 ms
42,032 KB
testcase_56 AC 358 ms
41,580 KB
testcase_57 AC 379 ms
41,260 KB
testcase_58 AC 360 ms
40,640 KB
testcase_59 AC 372 ms
41,048 KB
testcase_60 AC 347 ms
40,028 KB
testcase_61 AC 362 ms
40,944 KB
testcase_62 AC 359 ms
40,256 KB
testcase_63 AC 357 ms
41,012 KB
testcase_64 AC 358 ms
40,920 KB
testcase_65 AC 346 ms
40,120 KB
testcase_66 AC 365 ms
41,588 KB
testcase_67 AC 371 ms
41,320 KB
testcase_68 AC 365 ms
41,248 KB
testcase_69 AC 354 ms
41,216 KB
testcase_70 AC 370 ms
40,924 KB
testcase_71 AC 362 ms
40,868 KB
testcase_72 AC 364 ms
40,504 KB
testcase_73 AC 366 ms
40,144 KB
testcase_74 AC 358 ms
39,984 KB
testcase_75 AC 350 ms
39,748 KB
testcase_76 AC 2 ms
4,380 KB
testcase_77 AC 31 ms
10,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	vector<pii> v; // sum, cnt
	vector<int> cnt(N + 1, INF);
	vector<int> pred;
	cnt[0] = 0;
	for (int i = 1; (1 + i) * i / 2 <= N; ++i) {
		const int s = (1 + i) * i / 2;
		pred.emplace_back(s);
		cnt[s] = 1;
	}
	for (int i : pred) for (int j : pred) if (i + j <= N) chmin(cnt[i + j], 2);
	int ans = cnt[N];
	for (int i : pred) chmin(ans, 1 + cnt[N - i]);
	for (int i : pred) for (int j : pred) if (i + j <= N) chmin(ans, 2 + cnt[N - i - j]);
	cout << ans << endl;
}
0