結果

問題 No.634 硬貨の枚数1
ユーザー imulan
提出日時 2018-01-28 04:30:46
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 860 bytes
コンパイル時間 1,815 ms
コンパイル使用メモリ 170,336 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-29 08:17:30
合計ジャッジ時間 4,857 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 75
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 10000001;
int f(int n){
    return n*(n+1)/2;
}

int solve(){
    int n;
    cin >>n;

    vector<int> c;
    rep(i,N){
        if(f(i+1)>N) break;
        c.pb(f(i+1));
        if(c.back() == n) return 1;
    }

    int C = c.size();
    rep(i,C)rep(j,C)if(c[i]+c[j]==n) return 2;
    return 3;
}

int main(){
    cout << solve() << endl;
    return 0;
}
0