QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#234079 | #5045. King | CSU2023# | WA | 252ms | 3808kb | C++14 | 1.4kb | 2023-11-01 13:45:35 | 2023-11-01 13:45:36 |
Judging History
answer
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::ios;
const int N = 2e5 + 5;
int n, p, ans, b[N], a[N];
int T_data;
template <class T>
inline void CkMax(T &x, T y) {x < y ? x = y : 0;}
inline int quick_pow(int x, int k)
{
int res = 1;
while (k)
{
if (k & 1)
res = 1ll * res * x % p;
x = 1ll * x * x % p;
k >>= 1;
}
return res;
}
inline int check(int x, int q)
{
int cnt = 0;
for (int i = x + 1; i <= n; ++i)
{
if (1ll * a[x] * q % p == a[i])
x = i, ++cnt;
}
return cnt;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
srand(time(0));
cin >> T_data;
while (T_data--)
{
cin >> n >> p;
for (int i = 1; i <= n; ++i)
cin >> a[i], b[i] = quick_pow(a[i], p - 2);
ans = 0;
for (int t = 1; t <= 200; ++t)
{
int k = 1ll * rand() * rand() % (n - 2) + 1;
CkMax(ans, 2 + check(k + 1, 1ll * a[k + 1] * b[k] % p));
CkMax(ans, 2 + check(k + 2, 1ll * a[k + 2] * b[k] % p));
CkMax(ans, 2 + check(k + 2, 1ll * a[k + 2] * b[k + 1] % p));
}
if (ans >= (n + 1 >> 1))
cout << ans << '\n';
else
cout << "-1\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3748kb
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: 252ms
memory: 3808kb
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 132 -1 187 163 114 114 131 -1 108 114 137 115 -1 165 115 142 165 -1 -1 108 129 -1 144 122 -1 110 146 190 159 134 -1 117 180 196 -1 -1 192 123 109 -1 106 153 103 -1 -1 103 169 -1 174 152 -1 181 113 132 -1 153 199 182 -1 177 152 177 162 -1 114 -1 -1 -1 113 127 -1 -1 -1 -1 167 166 -1 140 -1 -1 -1 12...
result:
wrong answer 2nd numbers differ - expected: '133', found: '132'