結果

問題 No.634 硬貨の枚数1
ユーザー siman
提出日時 2021-01-27 15:49:59
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 1,479 ms
コンパイル使用メモリ 141,940 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-24 17:33:53
合計ジャッジ時間 3,322 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 75
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<int> M;

  int k = 1;
  while (k * (k + 1) / 2 <= N) {
    M.push_back(k * (k + 1) / 2);
    ++k;
  }

  for (int i = 0; i < M.size(); ++i) {
    int a = M[i];

    if (a == N) {
      cout << 1 << endl;
      return 0;
    }
  }

  for (int i = 0; i < M.size(); ++i) {
    int a = M[i];

    for (int j = i; j < M.size(); ++j) {
      int b = M[j];
      int c = a + b;

      if (c == N) {
        cout << 2 << endl;
        return 0;
      }
    }
  }

  cout << 3 << endl;

  return 0;
}
0