結果

問題 No.2479 Sum of Squares
ユーザー ochiaigawaochiaigawa
提出日時 2023-09-22 21:27:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 903 bytes
コンパイル時間 1,966 ms
コンパイル使用メモリ 202,388 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 21:27:49
合計ジャッジ時間 3,301 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
long long sqr(long long x) {
  long long ret = sqrt(x);
  if(ret * ret > x) {
    ret--;
  }
  if((ret + 1) * (ret + 1) <= x) {
    ret++;
  }
  return ret;
}
vector<long long> ans;
bool ok = false;
void dfs(long long S, vector<long long> v) {
  if(ok) {
    return;
  }
  if(S == 0) {
    ans = v;
    ok = true;
    return;
  }
  if((int) v.size() > 15) {
    return;
  }
  long long T = sqr(S);
  for(int i = 0; i < 3; i++) {
    if(T - i > 0) {
      vector<long long> nv = v;
      nv.emplace_back((T - i) * (T - i));
      dfs(S - (T - i) * (T - i), nv);
    }
  }
}
int main() {
  cin.tie(0); cout.tie(0);
  ios::sync_with_stdio(false);
  long long S;
  cin >> S;
  dfs(S, vector<long long>{});
  cout << (int) ans.size() << '\n';
  for(int i = 0; i < (int) ans.size(); i++) {
    cout << ans[i] << " \n"[i == (int) ans.size() - 1];
  }
  return 0;
}
0