結果
| 問題 | No.3048 Swing |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-17 18:37:49 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,639 bytes |
| 記録 | |
| コンパイル時間 | 2,039 ms |
| コンパイル使用メモリ | 332,336 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2026-07-17 18:38:08 |
| 合計ジャッジ時間 | 4,326 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 WA * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define rep(i, s, t) for (ll i = (ll)s; i < (ll)(t); i++)
#define rrep(i, s, t) for (ll i = (ll)(t) - 1; i >= (ll)(s); i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template <class T1, class T2>
bool chmin(T1& x, T2 y) { return x > y ? (x = y, true) : false; }
template <class T1, class T2>
bool chmax(T1& x, T2 y) { return x < y ? (x = y, true) : false; }
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
using max_heap = priority_queue<T>;
void solve() {
ll X, N;
cin >> X >> N;
ll ok = 0, ng = 2 * (ll)sqrt(X) + 10;
while (ng - ok > 1) {
ll mid = (ok + ng) / 2;
if ((__int128_t)mid * (mid + 1) / 2 <= abs(X)) ok = mid;
else ng = mid;
}
if (N <= ok) {
if (X > 0) X -= (__int128_t)N * (N + 1) / 2;
else X += (__int128_t)N * (N + 1) / 2;
cout << X << "\n";
} else {
ll M = N;
if (X > 0) X -= (__int128_t)ok * (ok + 1) / 2;
else X += (__int128_t)ok * (ok + 1) / 2;
N -= ok;
if (X > 0) {
if (N % 2 == 0) X += N / 2;
else X += N / 2 - M;
} else {
if (N % 2 == 0) X -= N / 2;
else X -= N / 2 - M;
}
cout << X << "\n";
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(15);
srand(time(NULL));
int T;
// cin >> T;
T = 1;
while (T--) solve();
}