QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#538004#4565. Rarest InsectsYahia_Emara#0 10ms10292kbC++202.8kb2024-08-30 20:47:482024-08-30 20:47:48

Judging History

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

  • [2024-08-30 20:47:48]
  • 评测
  • 测评结果:0
  • 用时:10ms
  • 内存:10292kb
  • [2024-08-30 20:47:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define dbg(x) cout << (#x) << " : " << x << endl
#define pb push_back
#define bk(x) x.back()
#define all(x) x.begin(),x.end()
#define LOOP(n) for(int rp=0;rp<n;rp++)
#define sq(x) ((x)*(x))
typedef long long ll;
typedef long double dl;
const int SZ=5e5+7;
const ll INF=1e18+7;
const dl eps=1e-9;
int MOD=1e9+7;
mt19937_64 rng(time(0));
int rnd(int l,int r){
    return uniform_int_distribution<int>(l,r)(rng);
}
ll trig(ll x){
    return x*(x+1)/2;
}
int getN(){
    int n;cin >> n;
    return n;
}
#define cmbntrcs fact[0]=1;for(int i=1;i<SZ;i++)fact[i]=mul(fact[i-1],i);finv[SZ-1]=inv(fact[SZ-1]);for(int i=SZ-2;i>0;i--)finv[i]=mul(finv[i+1],i+1);
int fact[SZ],finv[SZ];
int add(int x,int y,int MOD=MOD){
    x+=y;if(x>=MOD)x-=MOD;
    return x;
}
int sub(int x,int y,int MOD=MOD){
    x-=y;if(x<0)x+=MOD;
    return x;
}
int mul(int x,int y,int MOD=MOD){
    return(x*1ll*y)%MOD;
}
int pwr(int x,ll b,int MOD=MOD){
    int rt=1;
    while(b>0){
        if(b&1)rt=mul(rt,x,MOD);
        x=mul(x,x,MOD),b>>=1;
    }
    return rt;
}
int inv(int x,int MOD=MOD){
    return pwr(x,MOD-2,MOD);
}
#include "insects.h"
//#include "stub.cpp"
int n,p[SZ],a[SZ],k,vs[SZ];
vector<int>v;
void ins(int i){
    i=p[i];
    vs[i]=1;
    move_inside(i);
    v.pb(i);
}
void dlt(){
    vs[bk(v)]=0;
    move_outside(bk(v));
    v.pop_back();
}
void permdlt(){
    vs[bk(v)]=2;
    move_outside(bk(v));
    v.pop_back();
}
int card(){
    return press_button();
}
bool f(int C){
    while(card()>C)dlt();
    for(int i=0;i<n;i++){
        if(vs[p[i]])continue;
        ins(i);
        if(card()>C)dlt();
    }
    if(C*k==sz(v))return 1;
    return 0;
}
int min_cardinality(int N){
    n=N;
    for(int i=0;i<n;i++)p[i]=i,swap(p[i],p[rnd(0,i)]);
    for(int i=0;i<n;i++){
        ins(i);
        if(card()>1)dlt();
    }
    k=sz(v);
    if(k==1)return n;
    if(k<=5){
        vector<int>w=v;
        while(sz(v))dlt();
        for(int i=0;i<k;i++)swap(w[i],w[rnd(0,i)]);
        int C=0,ans=1e9;
        for(int i=0;i<k-1;i++){
            ins(w[i]);
            for(int i=0;i<n;i++){
                if(vs[p[i]])continue;
                ins(i);
                if(card()!=sz(v))dlt();
            }
            C+=sz(v),ans=min(ans,sz(v));
            while(sz(v))dlt();
        }
        ans=min(ans,n-C);
        return ans;
    }
    int l=2,r=n/k,ans=1;
    dbg(ans);
    while(l<=r){
        int md=(l+r)>>1;
        dbg(md);
        if(f(md))l=md+1,ans=md;
        else r=md-1;
        dbg(ans);
    }
    dbg(ans);
    return ans;
}
/*int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    //cout << fixed << setprecision(12);
    int tt=1;
    //cin >> tt;
    LOOP(tt){
        //code
    }
    return 0;
}*/

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7960kb

input:

6
1
1
2
1
2
2
1
2
2
3
3
2
2
2
3
3

output:

8
0 2
8
2
8
0 0
8
2
8
0 5
8
2
8
1 5
8
0 1
8
2
8
0 4
8
2
8
1 4
8
0 3
8
2
8
1 3
8
1 1
8
1 0
8
1 2
8
0 2
8
0 0
8
2
8
1 0
8
0 5
8
2
8
0 1
8
2
8
1 1
8
0 4
8
2
8
0 3
8
2
8
1 3
8
1 4
8
1 5
8
1 2
8
0 5
8
0 2
8
2
8
0 0
8
2
8
1 0
8
0 1
8
2
8
1 1
8
0 4
8
2
8
0 3
8
2
8
1 3
8
1 4
8
1 2
8
1 5
8
3 0

result:

wrong answer Wrong answer.

Subtask #2:

score: 0
Wrong Answer

Test #24:

score: 15
Accepted
time: 4ms
memory: 10292kb

input:

1000
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2...

output:

8
0 407
8
2
8
0 341
8
2
8
1 341
8
0 478
8
2
8
1 478
8
0 484
8
2
8
1 484
8
0 622
8
2
8
1 622
8
0 178
8
2
8
1 178
8
0 604
8
2
8
1 604
8
0 500
8
2
8
1 500
8
0 370
8
2
8
1 370
8
0 760
8
2
8
1 760
8
0 155
8
2
8
1 155
8
0 731
8
2
8
1 731
8
0 140
8
2
8
1 140
8
0 497
8
2
8
1 497
8
0 43
8
2
8
1 43
8
0 838
8
...

result:

ok 

Test #25:

score: 0
Wrong Answer
time: 0ms
memory: 10272kb

input:

1000
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1...

output:

8
0 407
8
2
8
0 341
8
2
8
0 478
8
2
8
0 484
8
2
8
0 622
8
2
8
0 178
8
2
8
0 604
8
2
8
0 500
8
2
8
0 370
8
2
8
0 760
8
2
8
0 155
8
2
8
0 731
8
2
8
0 140
8
2
8
0 497
8
2
8
0 43
8
2
8
0 838
8
2
8
0 680
8
2
8
0 237
8
2
8
0 81
8
2
8
0 124
8
2
8
0 745
8
2
8
0 52
8
2
8
0 93
8
2
8
0 737
8
2
8
0 568
8
2
8
0 ...

result:

wrong answer Secret mismatch (possible tampering with the output)

Subtask #3:

score: 0
Wrong Answer

Test #43:

score: 75
Accepted
time: 1ms
memory: 9944kb

input:

2
1
2

output:

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

result:

ok 

Test #44:

score: 75
Accepted
time: 1ms
memory: 10004kb

input:

2
1
1
1

output:

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

result:

ok 

Test #45:

score: 75
Accepted
time: 1ms
memory: 10280kb

input:

3
1
1
2
2
2

output:

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

result:

ok 

Test #46:

score: 75
Accepted
time: 1ms
memory: 10236kb

input:

6
1
1
2
2
2
2
1
1
1
1
1

output:

8
0 2
8
2
8
0 0
8
2
8
0 5
8
2
8
1 5
8
0 1
8
2
8
1 1
8
0 4
8
2
8
1 4
8
0 3
8
2
8
1 3
8
1 0
8
1 2
8
0 2
8
0 0
8
2
8
1 0
8
0 5
8
2
8
1 5
8
0 1
8
2
8
1 1
8
0 4
8
2
8
1 4
8
0 3
8
2
8
1 3
8
1 2
8
3 1

result:

ok 

Test #47:

score: 75
Accepted
time: 1ms
memory: 9988kb

input:

10
1
1
2
2
2
2
2
2
2
2
1
2
2
2
3
4
4
4
4

output:

8
0 2
8
2
8
0 0
8
2
8
0 7
8
2
8
1 7
8
0 6
8
2
8
1 6
8
0 4
8
2
8
1 4
8
0 3
8
2
8
1 3
8
0 1
8
2
8
1 1
8
0 5
8
2
8
1 5
8
0 8
8
2
8
1 8
8
0 9
8
2
8
1 9
8
1 0
8
1 2
8
0 2
8
0 0
8
2
8
1 0
8
0 7
8
2
8
0 6
8
2
8
1 6
8
0 4
8
2
8
1 4
8
0 3
8
2
8
0 1
8
2
8
0 5
8
2
8
1 5
8
0 8
8
2
8
1 8
8
0 9
8
2
8
1 9
8
1 1
8
...

result:

ok 

Test #48:

score: 75
Accepted
time: 4ms
memory: 9992kb

input:

2000
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2...

output:

8
0 407
8
2
8
0 1875
8
2
8
1 1875
8
0 478
8
2
8
1 478
8
0 1968
8
2
8
1 1968
8
0 622
8
2
8
1 622
8
0 1273
8
2
8
1 1273
8
0 1486
8
2
8
1 1486
8
0 500
8
2
8
1 500
8
0 1519
8
2
8
1 1519
8
0 1708
8
2
8
1 1708
8
0 1012
8
2
8
1 1012
8
0 1102
8
2
8
1 1102
8
0 140
8
2
8
1 140
8
0 497
8
2
8
1 497
8
0 43
8
2
8...

result:

ok 

Test #49:

score: 0
Wrong Answer
time: 10ms
memory: 10012kb

input:

2000
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1...

output:

8
0 407
8
2
8
0 1875
8
2
8
0 478
8
2
8
0 1968
8
2
8
0 622
8
2
8
0 1273
8
2
8
0 1486
8
2
8
0 500
8
2
8
0 1519
8
2
8
0 1708
8
2
8
0 1012
8
2
8
0 1102
8
2
8
0 140
8
2
8
0 497
8
2
8
0 43
8
2
8
0 838
8
2
8
0 1431
8
2
8
0 237
8
2
8
0 81
8
2
8
0 1294
8
2
8
0 745
8
2
8
0 52
8
2
8
0 93
8
2
8
0 1226
8
2
8
0 5...

result:

wrong answer Secret mismatch (possible tampering with the output)