QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#152993#6399. Classic: Classical ProblemaestheticWA 2ms3744kbC++143.2kb2023-08-29 07:12:152023-08-29 07:12:17

Judging History

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

  • [2023-08-29 07:12:17]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3744kb
  • [2023-08-29 07:12:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
typedef pair<int, int> pii;
const ll inf=LLONG_MAX;
const int maxn=1e5+10;

mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
int rand(int a, int b) {
    return a + rng()%(b-a+1);
}

int modInv(int a, int m)
{
    int m0=m;
    int y=0, x=1;
    if(m==1)
        return 0;
    while(a>1)
    {
        int q=a/m;
        int t=m;
        m=a%m, a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0)
        x+=m0;
    return x;
}

int n, p;
int mark[maxn];
int in[maxn];

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout); 
    #endif
    ios::sync_with_stdio(0);cin.tie(0);

    int T; cin>> T;
    while(T--)
    {
        cin>> n>> p;
        for(int i=0; i<p; i++)
            mark[i]=0;
        vector<int> v;
        for(int i=0; i<n; i++)
        {
            int ai; cin>> ai;
            v.pb(ai);
            mark[ai]=1;
        }
        if(!mark[0])
        {
            cout<< "1 1\n0\n";
            continue;
        }
        if(n==1)
        {
            cout<< p<< " 1\n";
            for(int i=0; i<p; i++)
                cout<< i<< " ";
            cout<< "\n";
            continue;
        }
        if(n==p)
        {
            cout<< p<< " "<< p-1<< "\n";
            for(int i=1; i<p; i++)
                cout<< i<< " ";
            cout<< "\n";
            continue;
        }
        for(int i=1; i<p; i++)
            in[i]=modInv(i, p);
        shuffle(v.begin(), v.end(), rng);
        // for(int x: v)
        //     cout<< x<< " ";
        // cout<< "\n";
        int best=-1;
        int idmx=-1;
        for(int i=0; i<n; i++)
        {
            int x=v[i];
            if(!x)
                continue;
            // cout<< i<< " "<< x<< " "<< best<< "\n";
            bool better=true;
            int test=best+1;
            while(test>=2)
            {
                if(mark[test*x%p])
                    test--;
                else
                {
                    better=false;
                    break;
                }
            }
            if(better)
            {
                while(best+1<p && mark[(best+1)*x%p])
                    best++;
                idmx=i;
            }
        }
        vector<int> ans;
        ans.pb(in[v[idmx]]);
        for(int i=idmx+1; i<n; i++)
        {
            int x=v[i];
            if(!x)
                continue;
            bool maximum=true;
            int test=best;
            while(test>=2)
            {
                if(mark[test*x%p])
                    test--;
                else
                {
                    maximum=false;
                    break;
                }
            }
            if(maximum)
                ans.pb(in[v[i]]);
        }
        cout<< ans.size()<< " "<< best+1<< "\n";
        sort(ans.begin(), ans.end());
        for(int x: ans)
            cout<< x<< " ";
        cout<< "\n";
    }
 
    return 0;
}   

詳細信息

Test #1:

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

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: 2ms
memory: 3744kb

input:

3
1 2
0
1 2
1
2 2
1 0

output:

2 1
0 1 
1 1
0
2 1
1 

result:

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