結果

問題 No.550 夏休みの思い出(1)
ユーザー mdj982mdj982
提出日時 2018-03-10 20:41:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 2,546 bytes
コンパイル時間 881 ms
コンパイル使用メモリ 106,000 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-04 20:14:48
合計ジャッジ時間 3,428 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
4,376 KB
testcase_01 AC 13 ms
4,376 KB
testcase_02 AC 12 ms
4,380 KB
testcase_03 AC 13 ms
4,380 KB
testcase_04 AC 12 ms
4,376 KB
testcase_05 AC 13 ms
4,380 KB
testcase_06 AC 14 ms
4,380 KB
testcase_07 AC 13 ms
4,376 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 12 ms
4,380 KB
testcase_10 AC 12 ms
4,380 KB
testcase_11 AC 12 ms
4,380 KB
testcase_12 AC 13 ms
4,376 KB
testcase_13 AC 13 ms
4,376 KB
testcase_14 AC 12 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 13 ms
4,380 KB
testcase_17 AC 11 ms
4,380 KB
testcase_18 AC 12 ms
4,384 KB
testcase_19 AC 12 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 12 ms
4,380 KB
testcase_23 AC 12 ms
4,380 KB
testcase_24 AC 13 ms
4,380 KB
testcase_25 AC 12 ms
4,376 KB
testcase_26 AC 12 ms
4,380 KB
testcase_27 AC 12 ms
4,376 KB
testcase_28 AC 12 ms
4,376 KB
testcase_29 AC 13 ms
4,380 KB
testcase_30 AC 13 ms
4,376 KB
testcase_31 AC 12 ms
4,380 KB
testcase_32 AC 12 ms
4,380 KB
testcase_33 AC 12 ms
4,380 KB
testcase_34 AC 12 ms
4,376 KB
testcase_35 AC 13 ms
4,380 KB
testcase_36 AC 13 ms
4,380 KB
testcase_37 AC 13 ms
4,376 KB
testcase_38 AC 12 ms
4,380 KB
testcase_39 AC 13 ms
4,376 KB
testcase_40 AC 13 ms
4,380 KB
testcase_41 AC 12 ms
4,376 KB
testcase_42 AC 12 ms
4,384 KB
testcase_43 AC 13 ms
4,380 KB
testcase_44 AC 13 ms
4,376 KB
testcase_45 AC 13 ms
4,376 KB
testcase_46 AC 13 ms
4,384 KB
testcase_47 AC 13 ms
4,380 KB
testcase_48 AC 13 ms
4,376 KB
testcase_49 AC 1 ms
4,384 KB
testcase_50 AC 1 ms
4,376 KB
testcase_51 AC 6 ms
4,376 KB
testcase_52 AC 13 ms
4,380 KB
testcase_53 AC 12 ms
4,380 KB
testcase_54 AC 13 ms
4,376 KB
testcase_55 AC 13 ms
4,380 KB
testcase_56 AC 13 ms
4,376 KB
testcase_57 AC 12 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#define _USE_MATH_DEFINES
#include <cmath>
#include <complex>

using namespace std;

#define INFD numeric_limits<double>::infinity()
#define INFL (int)1e8
#define INFLL (long long)1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

/*******************************************************/

vll divisors(ll x) {
  vll ret;
  Loopll1(i, x) {
    if (i > 1e6) break;
    ll y = (ll)i * i;
    if (y >= x) {
      if (y == x) ret.push_back(i);
      break;
    }
    else {
      if (x % i == 0) {
        ret.push_back(i);
        ret.push_back(x / i);
      }
    }
  }
  return ret;
}

inline ll calc(ll a, ll b, ll c, ll x) {
  return x * (x * (x + a) + b) + c;
}

inline ll calc2(ll a, ll b, ll x) {
  return x * (x + a) + b;
}

int main() {
  ll a, b, c; cin >> a >> b >> c;
  vll ans;
  if (c == 0) {
    ans.push_back(0);
  }
  else {
    vll c_divs = divisors(abs(c));
    Loop(i, c_divs.size()) {
      if (calc(a, b, c, c_divs[i]) == 0) {
        ans.push_back(c_divs[i]);
        break;
      }
      if (calc(a, b, c, -c_divs[i]) == 0) {
        ans.push_back(-c_divs[i]);
        break;
      }
    }
    a += ans[0];
    b += a * ans[0];
    c += b * ans[0];
  }
  ll buf[2];
  buf[0] = (-a + sqrt(a * a - 4 * b)) / 2;
  buf[1] = (-a - sqrt(a * a - 4 * b)) / 2;
  Loop(i, 2) {
    Loop(j, 3) {
      if (calc2(a, b, buf[i] + j - 1) == 0) {
        ans.push_back(buf[i] + j - 1);
      }
    }
  }
  sort(ans.begin(), ans.end());
  Loop(i, ans.size()) {
    if (i > 0 && ans[i] == ans[i - 1]) continue;
    cout << ans[i] << " ";
  }
  cout << endl;
}
0