QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#168658 | #5045. King | pooty# | WA | 191ms | 5920kb | C++20 | 1.2kb | 2023-09-08 18:32:15 | 2023-09-08 18:32:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
long long A[200000], iA[200000], M;
map<long long, long long> m, s;
long long pw(long long i, long long p) {
if (!p) return 1;
if (p == 1) return i;
return pw(i * i % M, p / 2) * (p % 2 ? i : 1) % M;
}
int main() {
//freopen("in.txt", "r", stdin);
long long T;
scanf("%lld", &T);
while (T--) {
long long N, w = 0, i, j;
scanf("%lld %lld", &N, &M);
for (i = 0; i < N; ++i) scanf("%lld", &A[i]), iA[i] = pw(A[i], M - 2);
for (i = 1; i <= 4; ++i) for (j = 0; j + i < N; ++j) ++m[A[j + i] * iA[j] % M];
for (auto it = m.begin(); it != m.end(); ++it) if (it->second >= N / 4) {
long long z = it->first, zi = pw(z, M - 2);
for (i = 0; i < N; ++i) {
auto rt = s.find(A[i] * zi % M);
long long t = (rt != s.end() ? rt->second : 0);
s[A[i]] = max(s[A[i]], t + 1);
w = max(w, t + 1);
}
s.clear();
if (w >= (N + 1) / 2) break;
}
m.clear();
printf("%lld\n", w >= (N + 1) / 2 ? w : -1);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3592kb
input:
4 6 1000000007 1 1 2 4 8 16 6 1000000007 597337906 816043578 617563954 668607211 89163513 464203601 5 1000000007 2 4 5 6 8 5 1000000007 2 4 5 6 7
output:
5 -1 3 -1
result:
ok 4 number(s): "5 -1 3 -1"
Test #2:
score: -100
Wrong Answer
time: 191ms
memory: 5920kb
input:
1000 200 495189361 193302375 262009153 248101278 250233641 303504256 426913173 23261177 206011896 214770731 286184509 492688635 207979481 282629026 450810670 41818047 359796006 445343921 241742611 249404909 41291916 392252331 125287519 92825425 162555413 371172157 420486666 270651384 309213995 11709...
output:
-1 133 -1 187 163 114 114 132 100 108 116 137 115 -1 165 115 142 165 -1 -1 108 129 -1 144 122 -1 111 146 190 159 134 -1 117 180 196 -1 -1 192 123 110 -1 106 153 103 -1 -1 103 169 -1 174 152 -1 181 113 135 -1 153 199 182 -1 177 152 177 162 -1 115 -1 -1 -1 113 128 -1 -1 -1 -1 168 167 -1 140 -1 -1 -1 1...
result:
wrong answer 131st numbers differ - expected: '199', found: '100'