結果

問題 No.984 Inversion
ユーザー square1001square1001
提出日時 2020-03-02 00:24:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 913 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 67,552 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 22:27:45
合計ジャッジ時間 1,560 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 3 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 3 ms
5,376 KB
testcase_13 WA -
testcase_14 AC 3 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 3 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 3 ms
5,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
5,376 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;
int solve(int P, int N) {
	if (P == 2) return 0;
	int B = 0;
	while (1LL * B * B < P) ++B;
	int pos = 0;
	for (int i = 1; i <= B; ++i) {
		int val = 1LL * i * N % P;
		if (val <= B) {
			pos = i;
			break;
		}
		else if (val >= P - B) {
			return solve(P, P - N) ^ (1LL * N * (N - 1) / 2 % 2);
		}
	}
	if (pos == -1) return -1;
	int delta = 1LL * pos * N % P;
	int ans = 0;
	for (int i = 0; i < pos; ++i) {
		long long ini = 1LL * i * N % P;
		for (int j = 0; j < 2; ++j) {
			long long L = 1LL * j * P + (P + 1) / 2, R = 1LL * j * P + P;
			long long pl = max(L - ini + P - 1, 0LL) / P, pr = max(R - ini + P - 1, 0LL);
			if (pl >= (P + 1) / 2) pl = (P + 1) / 2;
			if (pr >= (P + 1) / 2) pr = (P + 1) / 2;
			ans += pr - pl;
		}
	}
	return ans % 2;
}
int main() {
	int P, N;
	cin >> P >> N;
	int ans = solve(P, N);
	cout << ans << endl;
	return 0;
}
0