답안 #452064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
452064 2021-08-03T17:28:20 Z soba Martian DNA (BOI18_dna) C++14
100 / 100
955 ms 8344 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int const N = 2e5+3;
set<int>s;
int reqs[N] , arr[N] , cnt[N] , tmp[N];
int n , k , q , a , b;
bool check(int x)
{
    s.clear();
    memset(tmp , 0 , sizeof tmp);
    int r = x;
    for(int i = 0 ; i < x ; i++)
    {
        tmp[arr[i]]++;
    }
    for(int i = 0 ; i < k ; i++)
    {
        if(reqs[i]>tmp[i])
            s.insert(i);
    }
    if(s.empty())
        return true;
    set<int>::iterator it;
    while(r<n)
    {
        tmp[arr[r]]++;
        tmp[arr[r-x]]--;
        if(tmp[arr[r]]>=reqs[arr[r]] && s.find(arr[r])!=s.end())
        {
            it=s.find(arr[r]);
            s.erase(it);
        }
        if(tmp[arr[r-x]]<reqs[arr[r-x]]&&s.find(arr[r-x])==s.end())
        {
            s.insert(arr[r-x]);
        }
        if(s.empty())
            return true;
        r++;
    }
    return false;
}
int main()
{
    cin >> n >> k >> q;
    for(int i = 0 ; i < n ;i++)
    {
        cin >> arr[i];
        cnt[arr[i]]++;
    }
    bool flag =true;
    int l = 0 , r = n , mid;
    while(q--)
    {
        cin >> a >> b ;
        reqs[a]=b;
        l+=b;
        if(reqs[a]>cnt[a])
            flag=false;
    }
    if(!flag)
    {
        cout << "impossible";
        return 0;
    }
    int ans=n;
    while(l<=r)
    {
        mid=(l+r)>>1;
        //cout << mid << "\n";
        if(check(mid))
        {
            ans=min(ans , mid);
            r=mid-1;
        }
        else
            l=mid+1;
    }
    cout << ans ;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
3 Correct 1 ms 1100 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 1060 KB Output is correct
8 Correct 1 ms 1100 KB Output is correct
9 Correct 1 ms 1068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 2 ms 1100 KB Output is correct
3 Correct 3 ms 1100 KB Output is correct
4 Correct 3 ms 1100 KB Output is correct
5 Correct 3 ms 1100 KB Output is correct
6 Correct 3 ms 1100 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 1068 KB Output is correct
9 Correct 1 ms 1100 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 1068 KB Output is correct
13 Correct 1 ms 972 KB Output is correct
14 Correct 1 ms 1016 KB Output is correct
15 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 2244 KB Output is correct
2 Correct 57 ms 2244 KB Output is correct
3 Correct 52 ms 2268 KB Output is correct
4 Correct 59 ms 2244 KB Output is correct
5 Correct 98 ms 3292 KB Output is correct
6 Correct 37 ms 2172 KB Output is correct
7 Correct 43 ms 1632 KB Output is correct
8 Correct 138 ms 3928 KB Output is correct
9 Correct 92 ms 2836 KB Output is correct
10 Correct 74 ms 2328 KB Output is correct
11 Correct 2 ms 1100 KB Output is correct
12 Correct 2 ms 1100 KB Output is correct
13 Correct 3 ms 1084 KB Output is correct
14 Correct 3 ms 1100 KB Output is correct
15 Correct 3 ms 1100 KB Output is correct
16 Correct 3 ms 1100 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 972 KB Output is correct
20 Correct 1 ms 296 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 1 ms 1100 KB Output is correct
24 Correct 1 ms 972 KB Output is correct
25 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 127 ms 3920 KB Output is correct
2 Correct 558 ms 3872 KB Output is correct
3 Correct 226 ms 3628 KB Output is correct
4 Correct 36 ms 2244 KB Output is correct
5 Correct 123 ms 3364 KB Output is correct
6 Correct 955 ms 8344 KB Output is correct
7 Correct 99 ms 2884 KB Output is correct
8 Correct 307 ms 3348 KB Output is correct
9 Correct 70 ms 2236 KB Output is correct
10 Correct 62 ms 2340 KB Output is correct
11 Correct 54 ms 2208 KB Output is correct
12 Correct 58 ms 2252 KB Output is correct
13 Correct 97 ms 3344 KB Output is correct
14 Correct 38 ms 2220 KB Output is correct
15 Correct 42 ms 1644 KB Output is correct
16 Correct 140 ms 3824 KB Output is correct
17 Correct 95 ms 2936 KB Output is correct
18 Correct 73 ms 2208 KB Output is correct
19 Correct 2 ms 1100 KB Output is correct
20 Correct 2 ms 1100 KB Output is correct
21 Correct 3 ms 1076 KB Output is correct
22 Correct 3 ms 1100 KB Output is correct
23 Correct 3 ms 1100 KB Output is correct
24 Correct 3 ms 1100 KB Output is correct
25 Correct 1 ms 1100 KB Output is correct
26 Correct 1 ms 1072 KB Output is correct
27 Correct 1 ms 972 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 1 ms 972 KB Output is correct
31 Correct 2 ms 972 KB Output is correct
32 Correct 1 ms 1048 KB Output is correct
33 Correct 1 ms 972 KB Output is correct