QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#645812 | #6399. Classic: Classical Problem | crimsonsunset# | WA | 0ms | 3500kb | C++20 | 2.8kb | 2024-10-16 19:56:30 | 2024-10-16 19:56:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define int ll
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
mt19937 rnd(1329);
int mod;
int fastpow(int a, int b) {
if (b == 0) return 1;
int t = fastpow(a, b / 2);
t = 1ll * t * t % mod;
if (b % 2) {
t = 1ll * t * a % mod;
}
return t;
}
int lol(int a) {
return 1 * fastpow(a, mod - 2);
}
bool used[(int)2e5 + 10];
void solve() {
int n, p;
cin >> n >> p;
mod = p;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
for (auto e : a) used[e] = 1;
if (used[0] == 0) {
// cout << "lol ";
cout << "1 1\n0\n";
for (auto e : a) used[e] = 0;
return;
}
sort(all(a));
if (n == 1) {
for (auto e : a) used[e] = 0;
cout << p << ' ' << 1 << '\n';
for (int i = 0; i < p; ++i) cout << i << ' ';
cout << '\n';
return;
}
int ans = 0;
while (used[ans]) ans++;
set<int> anss; anss.insert(1);
if (ans == 1) anss.insert(0);
vector<int> nota;
for (int i = 0; i < n - 1; ++i) for (int j = a[i]; j < a[i + 1]; ++j) nota.push_back(j);
for (int j = a[n - 1] + 1; j < p; ++j) nota.push_back(j);
vector<int> ord(p);
iota(all(ord), 0);
for (auto x : ord) {
if (x == 0) continue;
if (!used[1ll * x * fastpow(x, mod - 2) % mod]) continue;
bool ok = 1;
// cout << x << '\n';
for (int i = 0; i < 300; ++i) {
if (ans == 1) break;
int j = rnd() % (ans - 1) + 1;
if (used[1ll * j * fastpow(x, mod - 2) % mod]) continue;
ok = 0;
break;
}
for (int i = 0; i < 300; ++i) {
if (ans == 1) break;
int j = nota[rnd() % (nota.size())];
if (j * x < ans) {
ok = 0;
break;
}
}
if (!ok) continue;
for (int j = 1; j < ans; ++j) {
if (used[1ll * j * fastpow(x, mod - 2) % mod]) continue;
ok = 0;
break;
}
if (!ok) continue;
if (ans == p) {
anss.insert(x);
continue;
}
if (used[1ll * ans * fastpow(x, mod - 2) % mod]) {
anss.clear();
while (ans < p && used[1ll * ans * fastpow(x, mod - 2) % mod]) ans++;
}
anss.insert(x);
}
cout << anss.size() << ' ' << ans << '\n';
for (auto e : anss) cout << e << ' '; cout << '\n';
for (auto e : a) used[e] = 0;
}
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int t;
cin >> t;
while (t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3500kb
input:
3 2 3 0 2 3 5 2 3 4 3 5 0 2 3
output:
2 1 0 1 1 1 0 2 1 0 1
result:
wrong answer 1st lines differ - expected: '1 2', found: '2 1'