QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#373228#6399. Classic: Classical ProblemQingyyxWA 0ms7940kbC++173.4kb2024-04-01 11:41:402024-04-01 11:41:42

Judging History

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

  • [2024-04-01 11:41:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:7940kb
  • [2024-04-01 11:41:40]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define enl putchar('\n')
#define all(x) (x).begin(),(x).end()
#define debug(x) printf(" "#x":%d\n",x);
using namespace std;
const int MAXN = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int mod = 998244353;
typedef pair<int, int> pii;
char buf[1 << 21], * p1 = buf, * p2 = buf, obuf[1 << 21], * o = obuf, of[35];
#define gc()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline ll qpow(ll a, ll n) { ll res = 1; while (n) { if (n & 1)res = res * a % mod; n >>= 1; a = a * a % mod; }return res; }
inline int read() { int s = 0, f = 1; char c = gc(); for (; !isdigit(c); c = gc())if (c == '-')f = -1; for (; isdigit(c); c = gc())s = s * 10 + c - '0'; return s * f; }
inline void read(int* a, int n) { for (int i = 1; i <= n; ++i)a[i] = read(); }
inline int inal(char* s) { int n = 0; for (s[0] = gc(); !isalpha(s[0]); s[0] = gc()); for (; isalpha(s[n]); s[++n] = gc()); return s[n] = 0, n; }
inline void outd(int* a, int n) { for (int i = 1; i <= n; ++i)printf("%d ", a[i]); enl; }
ll exgcd(ll a, ll b, ll& x, ll& y) {
    if (!b) { x = 1; y = 0; return a; }
    ll d = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int inv(int x) {
    ll t, r;
    exgcd(x, mod, t, r);
    return (t % mod + mod) % mod;
}
int n;
int a[MAXN]; bool vis[MAXN];
bool presolve() {
    if (!vis[0])
        return printf("1 1\n0\n");
    if (n == mod) {
        printf("%d %d\n", mod - 1, mod);
        for (int i = 1; i < mod; ++i)
            printf("%d ", i);
        enl;
        return true;
    }
    return false;
}
void solve() {
    n = read(), mod = read();
    memset(vis, 0, sizeof(bool) * mod);
    for (int i = 1; i <= n; ++i)vis[a[i] = read()] = 1;
    if (presolve())return;
    vector<int>ans;
    int mex = 0;
    if (mod - n >= 300) {
        for (int i = 1; i <= n; ++i) {
            if (!a[i])continue;
            for (int j = a[i], cnt = 1;; j = (j + a[i]) % mod, ++cnt) {
                if (!vis[j]) {
                    if (cnt >= mex) {
                        int iv = inv(a[i]);
                        if (cnt > mex)ans = { iv };
                        else ans.push_back(iv);
                        mex = cnt;
                    }
                    break;
                }
            }
        }
        sort(all(ans));
    } else {
        vector<int>vec;
        for (int i = 0; i < mod; ++i)
            if (!vis[i])vec.push_back(i);
        for (int i = 1; i < mod; ++i) {
            int mpos = inf;
            for (auto x : vec)
                mpos = min(1ll * mpos, 1ll * x * i % mod);
            if (mpos >= mex) {
                if (mpos > mex)ans = { i };
                else ans.push_back(i);
                mex = mpos;
            }
        }
    }
    printf("%d %d\n", ans.size(), mex);
    for (auto x : ans)
        printf("%d ", x);
    enl;
}
signed main(signed argc, char const* argv[]) {
    clock_t c1 = clock();
#ifdef LOCAL
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif
    //=============================================================
    int TxT = read();
    while (TxT--)
        solve();
    //=============================================================
#ifdef LOCAL
    end :
    cerr << "Time Used:" << clock() - c1 << "ms" << endl;
#endif
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7940kb

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: 7860kb

input:

3
1 2
0
1 2
1
2 2
1 0

output:

1 1
1 
1 1
0
1 2
1 

result:

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