結果
| 問題 |
No.3048 Swing
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2025-03-07 21:42:23 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,134 bytes |
| コンパイル時間 | 3,919 ms |
| コンパイル使用メモリ | 276,412 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 02:24:32 |
| 合計ジャッジ時間 | 4,418 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 62 |
ソースコード
#if __INCLUDE_LEVEL__ == 0
#include __BASE_FILE__
void Solve() {
int64_t x0, n;
IN(x0, n);
if (x0 > 0) {
// x0 以上
int64_t ng = 0;
int64_t ok = 1.5e9;
while (ng + 1 < ok) {
int64_t mid = midpoint(ng, ok);
(mid * (mid + 1) / 2 >= x0 ? ok : ng) = mid;
}
if (n <= ok) {
x0 -= n * (n + 1) / 2;
OUT(x0);
return;
}
x0 -= ok * (ok + 1) / 2;
assert(x0 <= 0);
// ok+1, ..., n
if ((n - ok) % 2 == 0) {
x0 -= (n - ok) / 2;
} else {
x0 -= (n - ok - 1) / 2;
x0 += n;
}
OUT(x0);
} else {
// -x0 より大
int64_t ng = 0;
int64_t ok = 1.5e9;
while (ng + 1 < ok) {
int64_t mid = midpoint(ng, ok);
(mid * (mid + 1) / 2 > -x0 ? ok : ng) = mid;
}
if (n <= ok) {
x0 += n * (n + 1) / 2;
OUT(x0);
return;
}
x0 += ok * (ok + 1) / 2;
assert(x0 > 0);
// ok+1, ..., n
if ((n - ok) % 2 == 0) {
x0 += (n - ok) / 2;
} else {
x0 += (n - ok - 1) / 2;
x0 -= n;
}
OUT(x0);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
Solve();
}
#elif __INCLUDE_LEVEL__ == 1
#include <bits/stdc++.h>
template <class T> concept MyRange = std::ranges::range<T> && !std::convertible_to<T, std::string_view>;
template <class T> concept MyTuple = std::__is_tuple_like<T>::value && !MyRange<T>;
namespace std {
istream& operator>>(istream& is, MyRange auto&& r) {
for (auto&& e : r) is >> e;
return is;
}
istream& operator>>(istream& is, MyTuple auto&& t) {
apply([&](auto&... xs) { (is >> ... >> xs); }, t);
return is;
}
ostream& operator<<(ostream& os, MyRange auto&& r) {
auto sep = "";
for (auto&& e : r) os << exchange(sep, " ") << e;
return os;
}
ostream& operator<<(ostream& os, MyTuple auto&& t) {
auto sep = "";
apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t);
return os;
}
} // namespace std
using namespace std;
#define IN(...) (cin >> forward_as_tuple(__VA_ARGS__))
#define OUT(...) (cout << forward_as_tuple(__VA_ARGS__) << '\n')
#endif // __INCLUDE_LEVEL__ == 1
risujiroh