結果

問題 No.3048 Swing
コンテスト
ユーザー vjudge1
提出日時 2025-03-09 02:50:46
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 170µs
コード長 670 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,244 ms
コンパイル使用メモリ 210,568 KB
実行使用メモリ 9,392 KB
最終ジャッジ日時 2026-07-12 10:52:05
合計ジャッジ時間 3,518 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 62
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3fLL;
const int MAX=2e5+10;
const int mod=998244353;
int main()
{
	ll x,n,now,i,target;
	scanf("%lld%lld",&x,&n);
	if(x==0)
	{
		x-=n/2;
		now=n/2*2;
	}
	else
	{
		if(x<0) target=-x;
		else target=x;
		now=sqrt(2*target);
		while((1+now)*now/2>=target) now--;
		while((1+now)*now/2<=target) now++;
		now=min(n,now-1);
		if(x>=0) x-=(1+now)*now/2;
		else x+=(1+now)*now/2;
		if(x<=0 && now<n)
		{
			now++;
			x+=now;
		}
		x+=(n-now)/2;
	}
	for(i=now+(n-now)/2*2+1;i<=n;i++)
	{
		if(x<=0) x+=i;
		else x-=i;
	}
	printf("%lld\n",x);
	return 0;
}
0