結果
問題 | No.984 Inversion |
ユーザー |
![]() |
提出日時 | 2020-03-02 00:39:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,364 bytes |
コンパイル時間 | 504 ms |
コンパイル使用メモリ | 69,164 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-13 20:53:43 |
合計ジャッジ時間 | 1,505 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 WA * 3 |
ソースコード
#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 * (P - 1) * (P - 2) / 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 + delta - 1, 0LL) / delta * pos + i, pr = max(R - ini + delta - 1, 0LL) / delta * pos + i;if (pl >= (P + 1) / 2) pl = ((P + 1) / 2 + pos - 1 - i) / pos * pos + i;if (pr >= (P + 1) / 2) pr = ((P + 1) / 2 + pos - 1 - i) / pos * pos + i;ans += (pr - pl) / pos;}}return ans % 2;}int solve_easy(int P, int N) {int ans = 0;for (int i = 1; i < P; ++i) {for (int j = i + 1; j < P; ++j) {if (1LL * i * N % P > 1LL * j * N % P) {ans ^= 1;}}}return ans;}bool isprime(int n) {if (n <= 1) return false;for (int i = 2; i * i <= n; ++i) {if (n % i == 0) return false;}return true;}int main() {int P, N;cin >> P >> N;int ans = solve(P, N);cout << ans << endl;return 0;}