結果

問題 No.2132 1 or X Game
ユーザー 👑 rin204rin204
提出日時 2022-11-25 22:12:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 725 bytes
コンパイル時間 2,336 ms
コンパイル使用メモリ 194,472 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 03:21:38
合計ジャッジ時間 9,656 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;

long long modpow(long long a, long long b){
	long long ret = 1;
	a %= MOD;
	while(b){
		if(b & 1){
			ret *= a;
			ret %= MOD;
		}
		a *= a;
		a %= MOD;
		b >>= 1;
	}
	return ret;
}

void solve(){
	long long n, x, ans;
	cin >> n >> x;
	if(x & 1){
		ans = (n + 1) / 2;
	}
	else{
		long long  c = n / (2 * x + 2);
		n %= (2 * x + 2);
		/*
		0: lose
		1 ~ x : odd
		x + 1 ~ 2x: even
		2x + 1: win 
		*/
		ans = (x + 1) * c;
		if(n <= x){
			ans += (n + 1) / 2;
		}
		else{
			ans += (x + 1) / 2;
			n -= x;
			ans += n / 2;
			if(n == x + 1) ans++;

		}
	}
	cout << ans % MOD << "\n";
}

int main(){
	int t;
	t = 1;
	cin >> t;
	while(t--) solve();
}
0