QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#528620 | #6399. Classic: Classical Problem | OneWan | WA | 0ms | 3616kb | C++23 | 1.7kb | 2024-08-23 17:03:02 | 2024-08-23 17:03:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
i64 Exgcd(i64 a, i64 b, i64 &x, i64 &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
i64 d = Exgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
int nxt1[200005];
void solve() {
int n, p;
cin >> n >> p;
set<int> st;
for (int i = 0 ; i < n ; i++) {
int x;
cin >> x;
st.insert(x);
}
if (n == p) {
cout << p << " " << n << "\n";
for (int i = 0 ; i < p ; i++) {
cout << i << " ";
}
cout << "\n";
return;
}
if (!st.count(0)) {
cout << 1 << " " << 1 << "\n";
cout << "0\n";
return;
}
for (int i = 1 ; i < p ; i++) {
i64 x, y;
i64 g = Exgcd(i, p, x, y);
x /= g;
y /= g;
g = p / g;
x = (x % g + g) % g;
nxt1[i] = x;
}
vector<int> vec;
for (int i = 1 ; i < p ; i++) {
vec.push_back(i);
}
int mex = 1;
while (true) {
vector<int> temp;
// cerr << mex << ":\n";
for (auto &x : vec) {
// cerr << x << " " << nxt1[x] << "\n";
if (st.count(1LL * nxt1[x] * mex % p)) {
temp.push_back(x);
}
}
if (temp.empty()) {
break;
}
mex++;
vec.swap(temp);
}
cout << vec.size() << " " << mex << "\n";
for (auto &x : vec) {
cout << x << " ";
}
cout << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
input:
3 2 3 0 2 3 5 2 3 4 3 5 0 2 3
output:
1 2 2 1 1 0 2 2 2 3
result:
ok 6 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3616kb
input:
3 1 2 0 1 2 1 2 2 1 0
output:
1 1 1 1 1 0 2 2 0 1
result:
wrong answer 1st lines differ - expected: '2 1', found: '1 1'