結果
問題 |
No.3048 Swing
|
ユーザー |
|
提出日時 | 2025-03-07 21:21:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,631 bytes |
コンパイル時間 | 1,401 ms |
コンパイル使用メモリ | 162,864 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-06-20 02:23:47 |
合計ジャッジ時間 | 2,614 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 62 |
ソースコード
#include <bits/stdc++.h> #define F first #define S second #define all(x) begin(x), end(x) #define pb push_back #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #ifdef LOCAL #define HEHE freopen("in.txt", "r", stdin); #define debug(HEHE...) cerr << #HEHE << " = ", dout(HEHE) void dout() { std::cerr << '\n'; } template <typename T, typename ...U> void dout(T t, U ...u) { std::cerr << t << ' '; dout(u...); } #else #define HEHE ios_base::sync_with_stdio(0), cin.tie(0); #define debug(...) 7122 #endif using namespace std; #define chmax(a, b) (a) = (a) > (b) ? (a) : (b) #define chmin(a, b) (a) = (a) < (b) ? (a) : (b) #define int long long signed main() { HEHE // 2 // 2 - 1 - 2 +3-4+5-6 // int x, n; cin >> x >> n; if (x <= 0 and n <= 2e9 and x + (n + 1) * n / 2 <= 0) { cout << x + (n + 1) * n / 2 << '\n'; return 0; } if (x > 0 and n <= 2e9 and x - (n + 1) * n / 2 > 0) { cout << x - (n + 1) * n / 2 << '\n'; return 0; } int t = sqrt((abs(x) + 1)*2) + 10; if (x <= 0) { while (x + t * (t + 1) / 2 > 0) t--; x += t * (t + 1) / 2; // x + (t+1) - (t+2)... if ((t+1+n) % 2) { cout << x - (n - t) / 2 << '\n'; } else { cout << x - (n - 1 - t) / 2 + n << '\n'; } } else { while (x <= t * (t + 1) / 2) t--; x -= t * (t + 1) / 2; // cout << x << '\n'; if ((t+1+n) % 2) { cout << x + (n - t) / 2 << '\n'; } else { cout << x + (n - 1 - t) / 2 - n << '\n'; } } // t + 1 ~n }