結果
問題 | No.3048 Swing |
ユーザー |
|
提出日時 | 2025-03-07 21:13:15 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 901 bytes |
コンパイル時間 | 1,772 ms |
コンパイル使用メモリ | 191,676 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 02:23:30 |
合計ジャッジ時間 | 3,121 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 62 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll x, n; cin >> x >> n; ll ok = 0, ng = 1ll << 31; while(ok + 1 < ng){ ll mid = (ok + ng) / 2; ll s = mid * (mid + 1) / 2; (s <= abs(x) ? ok : ng) = mid; } if(n <= ok){ if(x > 0){ x -= n * (n + 1) / 2; }else{ x += n * (n + 1) / 2; } cout << x << '\n'; return 0; } if(x > 0){ x -= ok * (ok + 1) / 2; }else{ x += ok * (ok + 1) / 2; } //cerr << x << " " << ok << '\n'; // ok + 1 -> n ll len = n - ok; if(len & 1){ if(x > 0){ x -= ok + 1; }else{ x += ok + 1; } } if(x > 0){ x += len / 2; }else{ x -= len / 2; } cout << x << '\n'; }