結果
問題 |
No.3048 Swing
|
ユーザー |
![]() |
提出日時 | 2025-03-07 21:19:53 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,265 bytes |
コンパイル時間 | 8,374 ms |
コンパイル使用メモリ | 373,812 KB |
実行使用メモリ | 8,612 KB |
最終ジャッジ日時 | 2025-03-07 21:20:04 |
合計ジャッジ時間 | 9,854 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 55 WA * 3 |
ソースコード
#include <iostream> using namespace std; #include <boost/multiprecision/cpp_int.hpp> typedef boost::multiprecision::cpp_int bint; const long long linf = 4610000000000000000; int main() { bint x, n; cin >> x >> n; if (0 <= x) { bint l = 0, r = (bint)linf * (bint)linf; while (abs(l - r) > 1) { bint c = (l + r) / 2; if (x - c * (c+1) / 2 > 0) { l = c; } else { r = c; } } if (n <= l) { cout << x - n * (n+1) / 2 << '\n'; } else { bint ans = x - l * (l+1) / 2; ans += (n - l) / 2; if ((n - l) % 2 == 1) { ans -= n; } cout << ans << '\n'; } } else { bint l = 0, r = (bint)linf * (bint)linf; while (abs(l - r) > 1) { bint c = (l + r) / 2; if (x + c * (c+1) / 2 <= 0) { l = c; } else { r = c; } } if (n <= l) { cout << x + n * (n+1) / 2 << '\n'; } else { bint ans = x + l * (l+1) / 2; ans -= (n - l) / 2; if ((n - l) % 2 == 1) { ans += n; } cout << ans << '\n'; } } return 0; } /* File : ~/yukicoder/526/A.cpp Date : 2025/03/07 Time : 21:02:05 */