Submission #554933

# Submission time Handle Problem Language Result Execution time Memory
554933 2022-04-29T16:14:53 Z new_acc Martian DNA (BOI18_dna) C++14
100 / 100
97 ms 3960 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=1e6+10;
const int SS=1<<19;
const int INFi=2e9;
const ll INFl=1e13;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=1000696969;
const ll p=70032301;
const ull p2=1e6+17;
const int L=20;
int t[N],lim[N],il[N],g[N];
ull pot[N];
void solve(){
    int n,k,m;
    cin>>n>>k>>m;
    for(int i=1;i<=n;i++) cin>>t[i];
    pot[0]=1;
    for(int i=1;i<=m;i++) pot[i]=pot[i-1]*p2;
    for(int i=0;i<k;i++) lim[i]=INFi;
    for(int a,b,i=1;i<=m;i++){
        cin>>a>>b;
        lim[a]=b,g[a]=i;
    }
    int res=-1,wsk=1;
    ull curr=0,total=0;
    for(int i=1;i<=m;i++) total+=pot[i];
    for(int i=1;i<=n;i++){
        wsk=max(wsk,i); 
        while(wsk<=n and curr!=total){
            il[t[wsk]]++;
            if(lim[t[wsk]]==il[t[wsk]]) curr+=pot[g[t[wsk]]];
            wsk++;
        }
        if(total==curr) res=(res==-1?wsk-i:min(res,wsk-i));
        il[t[i]]--; 
        if(lim[t[i]]==il[t[i]]+1) curr-=pot[g[t[i]]];
    }
    if(res==-1) cout<<"impossible\n";
    else cout<<res<<"\n";
}
int main(){
    int tt=1;
    //cin>>tt;
    while(tt--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1120 KB Output is correct
2 Correct 33 ms 1080 KB Output is correct
3 Correct 30 ms 1116 KB Output is correct
4 Correct 34 ms 972 KB Output is correct
5 Correct 59 ms 1752 KB Output is correct
6 Correct 29 ms 1080 KB Output is correct
7 Correct 35 ms 1640 KB Output is correct
8 Correct 57 ms 3948 KB Output is correct
9 Correct 47 ms 2120 KB Output is correct
10 Correct 29 ms 1508 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 320 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 312 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 2636 KB Output is correct
2 Correct 78 ms 2164 KB Output is correct
3 Correct 77 ms 1904 KB Output is correct
4 Correct 41 ms 1016 KB Output is correct
5 Correct 97 ms 2900 KB Output is correct
6 Correct 93 ms 3956 KB Output is correct
7 Correct 48 ms 1276 KB Output is correct
8 Correct 55 ms 1352 KB Output is correct
9 Correct 28 ms 1004 KB Output is correct
10 Correct 32 ms 996 KB Output is correct
11 Correct 32 ms 980 KB Output is correct
12 Correct 40 ms 1048 KB Output is correct
13 Correct 50 ms 1680 KB Output is correct
14 Correct 27 ms 1036 KB Output is correct
15 Correct 31 ms 1612 KB Output is correct
16 Correct 54 ms 3960 KB Output is correct
17 Correct 64 ms 2056 KB Output is correct
18 Correct 30 ms 1452 KB Output is correct
19 Correct 2 ms 304 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 2 ms 324 KB Output is correct
22 Correct 1 ms 388 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 304 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 304 KB Output is correct
33 Correct 1 ms 308 KB Output is correct