結果
問題 |
No.3048 Swing
|
ユーザー |
![]() |
提出日時 | 2025-03-14 15:28:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,545 bytes |
コンパイル時間 | 2,090 ms |
コンパイル使用メモリ | 194,912 KB |
実行使用メモリ | 7,324 KB |
最終ジャッジ日時 | 2025-03-14 15:28:45 |
合計ジャッジ時間 | 3,940 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 55 WA * 3 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } std::ostream &operator<<(std::ostream &dest, __int128_t value) { std::ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } } return dest; } int main() { fast_io(); __int128_t x, n; { long long xx, nn; cin >> xx >> nn; x = xx; n = nn; } bool swapped = x < 0; if (swapped) x = -x; if (x > n * (n + 1) / 2) { __int128_t ans = x - n * (n + 1) / 2; if (swapped) { ans = -ans; } cout << ans << endl; return 0; } __int128_t ok = 0, ng = n; while (ng - ok > 1) { __int128_t mid = (ok + ng) / 2; if (mid * (mid + 1) / 2 >= x) { ng = mid; } else { ok = mid; } } __int128_t ans = x - ok * (ok + 1) / 2; __int128_t res_op = n - ok; ans += res_op / 2; if (res_op % 2 == 1) { ans -= n; } if (swapped) { ans = -ans; } cout << ans << endl; }