QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#528620#6399. Classic: Classical ProblemOneWanWA 0ms3616kbC++231.7kb2024-08-23 17:03:022024-08-23 17:03:02

Judging History

你现在查看的是最新测评结果

  • [2024-08-23 17:03:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3616kb
  • [2024-08-23 17:03:02]
  • 提交

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'