結果
問題 |
No.3048 Swing
|
ユーザー |
![]() |
提出日時 | 2025-03-07 21:27:05 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,071 bytes |
コンパイル時間 | 5,810 ms |
コンパイル使用メモリ | 333,708 KB |
実行使用メモリ | 8,608 KB |
最終ジャッジ日時 | 2025-03-07 21:27:14 |
合計ジャッジ時間 | 7,419 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 29 WA * 29 |
ソースコード
#include <atcoder/all> #include <bits/stdc++.h> #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace atcoder; using namespace std; typedef long long ll; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); ll x, n; cin >> x >> n; auto check = [&](ll mid) { // ([...,1,1,1,0,0,0,...]) if (mid * (mid + 1) / 2 > x) return true; return false; }; auto binary = [&]() { ll ac = 1414213572, wa = 0; while (ac - wa > 1) { ll mid = (ac + wa) / 2; if (check(mid)) ac = mid; else wa = mid; } return ac; }; ll minus_ind = binary(); if (n <= minus_ind) { cout << x - n * (n + 1) / 2 << endl; return 0; } ll mi = x - minus_ind * (minus_ind + 1) / 2; ll pl = mi + minus_ind + 1; ll amari = n - minus_ind; ll ans; if (amari & 1LL) { ans = pl + amari / 2; } else { ans = mi - amari / 2; } cout << ans << endl; }