結果
問題 |
No.3048 Swing
|
ユーザー |
![]() |
提出日時 | 2025-03-07 21:31:53 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,234 bytes |
コンパイル時間 | 6,636 ms |
コンパイル使用メモリ | 333,376 KB |
実行使用メモリ | 8,612 KB |
最終ジャッジ日時 | 2025-03-07 21:32:02 |
合計ジャッジ時間 | 8,299 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; void output(__int128 x) { ll ans = x; cout << ans << endl; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); ll xx, nn; cin >> xx >> nn; __int128 x = xx, n = nn; auto check = [&](__int128 mid) { // ([...,1,1,1,0,0,0,...]) if (mid * (mid + 1) / 2 > x) return true; return false; }; auto binary = [&]() { __int128 ac = 1414213572, wa = 0; while (ac - wa > 1) { __int128 mid = (ac + wa) / 2; if (check(mid)) ac = mid; else wa = mid; } return ac; }; __int128 minus_ind = binary(); if (n <= minus_ind) { __int128 ans = x - n * (n + 1) / 2; output(ans); return 0; } __int128 mi = x - minus_ind * (minus_ind + 1) / 2; __int128 pl = mi + minus_ind + 1; __int128 amari = n - minus_ind; __int128 ans; if (amari & 1LL) { ans = pl + amari / 2; } else { ans = mi - amari / 2; } output(ans); }