답안 #927180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927180 2024-02-14T11:07:22 Z vjudge1 Martian DNA (BOI18_dna) C++17
40 / 100
2000 ms 15264 KB
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

#define int long long
#define ff first
#define ss second
#define pb push_back
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define no1 cout<<"-1\n"

using namespace std;

const int N = 2e5+100;
const int M = 1e5+10;
const int INF = 1e18;
const int mod = 1e9+7;
  
// int binpow (int a, int n) {
// 	if (n == 0)
// 		return 1;
// 	if (n % 2 == 1)
// 		return (binpow (a, n-1) * a)%mod;
// 	else {
// 		int b = binpow (a, n/2);
// 		return (b * b)%mod;
// 	}
// }

int n,k,R;
int a[N];
map<int,int> m;
pair<int,int> d[N];

bool ok(int x){
    m.clear();
    for(int i = 1;i<=x;i++){
        m[a[i]]++;
    }
    int l = 1;
    int r = x;
    while(r<=n){
        bool check = 1;
        for(int i = 1;i<=R;i++){
            if(m[d[i].ff]<d[i].ss){
                check = 0;
            }
        }
        if(check){
            return 1;
        }
        r++;
        m[a[r]]++;
        m[a[l]]--;
        l++;
    }
    return 0;
}

void solve(){
    cin>>n>>k>>R;
    for(int i = 1;i<=n;i++){
        cin>>a[i];
        m[a[i]]++;
    }
    for(int i = 1;i<=R;i++){
        cin>>d[i].ff>>d[i].ss;
        if(m[d[i].ff] < d[i].ss){
            cout<<"impossible\n";
            return;
        }
    }
    int l = 0;
    int r = n;
    while(r>l+1){
        int mid = (l+r)/2;
        if(ok(mid)) r = mid;
        else l = mid;
    }
    cout<<r<<'\n';
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    // cout.tie(nullptr);
    int t = 1; 
    // cin>>t;
    //   cout<<"";
    for(int i = 1;i<=t;i++){
        // cout<<"Case "<<i<<": ";
        solve();
        // cout<<'\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 8 ms 2668 KB Output is correct
4 Correct 14 ms 2648 KB Output is correct
5 Correct 8 ms 2396 KB Output is correct
6 Correct 4 ms 2480 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 2912 KB Output is correct
2 Correct 33 ms 2908 KB Output is correct
3 Correct 64 ms 2908 KB Output is correct
4 Correct 110 ms 2908 KB Output is correct
5 Correct 1577 ms 7924 KB Output is correct
6 Correct 79 ms 2908 KB Output is correct
7 Correct 14 ms 2904 KB Output is correct
8 Execution timed out 2082 ms 15264 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2021 ms 9960 KB Time limit exceeded
2 Halted 0 ms 0 KB -