結果

問題 No.634 硬貨の枚数1
ユーザー daleksprinter
提出日時 2018-09-10 02:47:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 665 bytes
コンパイル時間 2,071 ms
コンパイル使用メモリ 168,884 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-25 19:43:39
合計ジャッジ時間 3,374 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 75
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
const ll inf = 100100100100100;
const int mod = 1e9+7;

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n;
    cin >> n;
    vector<int> arr;

    int i = 1;
    while(i*(i+1)/2 <= n){
        arr.push_back(i*(i+1)/2);
        i++;
    }

    if(binary_search(arr.begin(), arr.end(), n)){
        cout << 1 << endl;
        return 0;
    }

    rep(i,0,arr.size()){
        if(binary_search(arr.begin(), arr.end(), n - arr[i])){
            cout << 2 << endl;
            return 0;
        }
    }

    cout << 3 << endl;

}
0