結果
問題 | No.3048 Swing |
ユーザー |
|
提出日時 | 2025-03-07 21:45:00 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 893 bytes |
コンパイル時間 | 1,968 ms |
コンパイル使用メモリ | 193,036 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-06-20 02:24:47 |
合計ジャッジ時間 | 3,685 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 62 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) void solve() { ll x, n; cin >> x >> n; auto s = [](ll i) -> ll { return (i + 1) * i / 2; }; ll i; { ll ok = 0, ng = 2e9; while (ok + 1 < ng) { ll m = (ok + ng) / 2; if (s(m) <= abs(x)) { ok = m; } else { ng = m; } } i = min(ok, n); } if (x <= 0) { x += s(i); } else { x -= s(i); } if (i == n) { cout << x << '\n'; return; } if (x <= 0) { i += 1; x += i; } ll ans; if ((n - i) % 2 == 0) { ans = x + (n - i) / 2; } else { i += 1; x -= i; ans = x - (n - i) / 2; } cout << ans << '\n'; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int T = 1; for (int t = 0; t < T; t++) { solve(); } return 0; }