QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#645433#6399. Classic: Classical Problemcrimsonsunset#WA 0ms3820kbC++202.1kb2024-10-16 18:21:222024-10-16 18:21:24

Judging History

This is the latest submission verdict.

  • [2024-10-16 18:21:24]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3820kb
  • [2024-10-16 18:21:22]
  • Submitted

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));
    a.resize(unique(all(a)) - a.begin());
    int ans = 0;
    while (used[ans]) ans++;
    set<int> anss; anss.insert(1);
    if (ans == 1) anss.insert(0);
    for (auto e : a) {
        if (e == 0) continue;
        bool ok = 1;
        int x = lol(e);
//        cout << x << '\n';
        for (int i = 0; i < 500; ++i) {
            if (ans == 1) break;
            int j = rnd() % (ans - 1) + 1;
            if (used[1ll * j * fastpow(x, mod - 2) % mod]) continue;
            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)]) {
            anss.clear();
            while (ans < p && used[1ll * ans * fastpow(x, mod - 2)]) 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: 100
Accepted
time: 0ms
memory: 3576kb

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: 0
Accepted
time: 0ms
memory: 3788kb

input:

3
1 2
0
1 2
1
2 2
1 0

output:

2 1
0 1 
1 1
0
1 2
1 

result:

ok 6 lines

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3820kb

input:

7
1 3
0
1 3
1
2 3
1 0
1 3
2
2 3
2 0
2 3
1 2
3 3
0 1 2

output:

2 1
0 1 
1 1
0
1 2
1 
1 1
0
1 2
2 
1 1
0
2 3
1 2 

result:

wrong answer 1st lines differ - expected: '3 1', found: '2 1'