結果
問題 | No.2066 Simple Math ! |
ユーザー | 👑 hos.lyric |
提出日時 | 2022-09-02 22:38:56 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,530 bytes |
コンパイル時間 | 867 ms |
コンパイル使用メモリ | 102,324 KB |
実行使用メモリ | 13,644 KB |
最終ジャッジ日時 | 2024-11-16 04:51:14 |
合計ジャッジ時間 | 46,493 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
13,636 KB |
testcase_01 | AC | 26 ms
10,144 KB |
testcase_02 | AC | 41 ms
13,636 KB |
testcase_03 | AC | 18 ms
10,024 KB |
testcase_04 | AC | 1,856 ms
13,644 KB |
testcase_05 | TLE | - |
testcase_06 | AC | 1,713 ms
13,636 KB |
testcase_07 | AC | 1,825 ms
10,024 KB |
testcase_08 | AC | 1,841 ms
13,640 KB |
testcase_09 | AC | 1,731 ms
10,016 KB |
testcase_10 | AC | 1,839 ms
13,640 KB |
testcase_11 | AC | 1,840 ms
6,816 KB |
testcase_12 | AC | 1,755 ms
6,824 KB |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | AC | 341 ms
6,816 KB |
testcase_20 | AC | 348 ms
6,816 KB |
testcase_21 | AC | 347 ms
6,816 KB |
testcase_22 | AC | 310 ms
6,820 KB |
testcase_23 | AC | 354 ms
6,816 KB |
testcase_24 | AC | 1,135 ms
6,816 KB |
testcase_25 | AC | 969 ms
6,816 KB |
testcase_26 | AC | 1,120 ms
6,820 KB |
testcase_27 | AC | 1,182 ms
6,824 KB |
testcase_28 | AC | 994 ms
6,816 KB |
testcase_29 | AC | 62 ms
6,816 KB |
testcase_30 | AC | 34 ms
6,820 KB |
testcase_31 | TLE | - |
ソースコード
#include <cassert> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; // using Int = long long; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } constexpr unsigned __int128 toUInt128(const char *s) { unsigned __int128 x = 0; for (; *s; ++s) x = x * 10 + (*s - '0'); return x; } constexpr __int128 toInt128(const char *s) { if (*s == '-') return -toInt128(s + 1); __int128 x = 0; for (; *s; ++s) x = x * 10 + (*s - '0'); return x; } unsigned __int128 inUInt128() { static char buf[41]; scanf("%s", buf); return toUInt128(buf); } __int128 inInt128() { static char buf[41]; scanf("%s", buf); return toInt128(buf); } void out(unsigned __int128 x) { static char buf[41]; int len = 0; do { buf[len++] = '0' + static_cast<int>(x % 10); } while (x /= 10); for (int i = len; --i >= 0; ) putchar(buf[i]); } void out(__int128 x) { if (x < 0) { putchar('-'); out(-static_cast<unsigned __int128>(x)); } else { out(static_cast<unsigned __int128>(x)); } } std::ostream &operator<<(std::ostream &os, unsigned __int128 x) { static char buf[41]; int len = 0; do { buf[len++] = '0' + static_cast<int>(x % 10); } while (x /= 10); for (int i = len; --i >= 0; ) os << buf[i]; return os; } std::ostream &operator<<(std::ostream &os, __int128 x) { if (x < 0) { os << '-' << -static_cast<unsigned __int128>(x); } else { os << static_cast<unsigned __int128>(x); } return os; } using Int = __int128; Int gcd(Int a, Int b) { return b ? gcd(b, a % b) : a; } inline Int floor(Int a, Int m) { return a / m - ((a % m < 0) ? 1 : 0); } Int sumFloors(Int m, Int a, Int b, Int l, Int r) { if (l > r) return 0; const Int q = floor(a, m); const Int aa = a - q * m; const Int ll = floor(aa * l + b, m) + 1; const Int rr = floor(aa * r + b, m); return q * ((r + 1) * r / 2 - l * (l - 1) / 2) + r * rr - (l - 1) * (ll - 1) + (rr - ll + 1) + sumFloors(aa, -m, b, ll, rr); } int main() { for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) { Int P = inInt128(); Int Q = inInt128(); const Int K = inInt128(); const Int G = gcd(P, Q); P /= G; Q /= G; Int lo = -1, hi = Q * K + 1; for (; lo + 1 < hi; ) { const Int mid = (lo + hi) / 2; const Int num = sumFloors(Q, -P, mid + Q, 0, min(mid / P, Q - 1)); ((num >= K + 1) ? hi : lo) = mid; } Int ans = hi; ans *= G; out(ans); puts(""); } #ifndef LOCAL break; #endif } return 0; }