結果

問題 No.634 硬貨の枚数1
ユーザー koyoprokoyopro
提出日時 2020-01-30 22:34:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,566 bytes
コンパイル時間 2,296 ms
コンパイル使用メモリ 147,936 KB
実行使用メモリ 290,836 KB
最終ジャッジ日時 2023-10-14 08:52:52
合計ジャッジ時間 20,396 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
159,200 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 46 ms
159,460 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 46 ms
159,232 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 45 ms
159,456 KB
testcase_12 WA -
testcase_13 AC 46 ms
159,304 KB
testcase_14 AC 71 ms
175,784 KB
testcase_15 AC 347 ms
290,532 KB
testcase_16 AC 138 ms
192,284 KB
testcase_17 AC 181 ms
225,344 KB
testcase_18 AC 132 ms
192,392 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 386 ms
290,596 KB
testcase_22 AC 282 ms
225,156 KB
testcase_23 AC 126 ms
192,288 KB
testcase_24 AC 46 ms
159,476 KB
testcase_25 AC 45 ms
159,476 KB
testcase_26 AC 45 ms
159,388 KB
testcase_27 AC 45 ms
159,544 KB
testcase_28 AC 46 ms
159,552 KB
testcase_29 AC 45 ms
159,540 KB
testcase_30 AC 46 ms
159,456 KB
testcase_31 AC 48 ms
159,464 KB
testcase_32 AC 46 ms
159,084 KB
testcase_33 AC 45 ms
159,396 KB
testcase_34 AC 57 ms
167,644 KB
testcase_35 AC 108 ms
192,272 KB
testcase_36 AC 217 ms
225,092 KB
testcase_37 AC 155 ms
192,392 KB
testcase_38 AC 63 ms
168,888 KB
testcase_39 AC 282 ms
225,160 KB
testcase_40 AC 208 ms
225,164 KB
testcase_41 AC 191 ms
225,152 KB
testcase_42 AC 269 ms
225,324 KB
testcase_43 AC 120 ms
192,220 KB
testcase_44 WA -
testcase_45 AC 48 ms
160,392 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 398 ms
290,504 KB
testcase_51 AC 62 ms
168,064 KB
testcase_52 WA -
testcase_53 AC 47 ms
159,036 KB
testcase_54 AC 46 ms
159,152 KB
testcase_55 AC 396 ms
290,592 KB
testcase_56 AC 397 ms
290,596 KB
testcase_57 AC 414 ms
290,712 KB
testcase_58 AC 388 ms
290,712 KB
testcase_59 AC 395 ms
290,432 KB
testcase_60 AC 388 ms
290,580 KB
testcase_61 AC 396 ms
290,624 KB
testcase_62 AC 392 ms
290,692 KB
testcase_63 AC 396 ms
290,680 KB
testcase_64 AC 389 ms
290,704 KB
testcase_65 AC 385 ms
290,544 KB
testcase_66 AC 394 ms
290,612 KB
testcase_67 AC 425 ms
290,648 KB
testcase_68 AC 391 ms
290,552 KB
testcase_69 AC 398 ms
290,608 KB
testcase_70 AC 395 ms
290,596 KB
testcase_71 AC 391 ms
290,544 KB
testcase_72 AC 392 ms
290,652 KB
testcase_73 AC 387 ms
290,836 KB
testcase_74 AC 386 ms
290,632 KB
testcase_75 AC 386 ms
290,652 KB
testcase_76 AC 47 ms
159,724 KB
testcase_77 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/

int N,M,Q;

int ans;
int MAX = 1e7;
vector<int> S; // 1枚で払える金額一覧
vector<int> D; // 2枚で払える金額一覧
vector<int> C(2e7, INT_MAX); // SorDに入っている金額のチェック用

int check(int n) {
    for (int m:S) {
        if (C[n-m]<INT_MAX) return 1 + C[n-m];
    }
    for (int m:D) {
        if (C[n-m]<INT_MAX) return 2 + C[n-m];
    }
    return -1;
}

void solve() {
    cin>>N;
    
    REP(i,sqrt(N)+2) {
        int n = i * (i+1) / 2;
        if (n > MAX) break;
        S.push_back(n);
        C[n] = 1;
    }
    for (int a:S) for (int b:S) {
        int n = a + b;
        if (n > MAX) break;
        if (C[n]==1) continue;
        D.push_back(n);
        C[n] = 2;
    }
    
    cout << check(N) << endl;
}
0