Submission #969165

# Submission time Handle Problem Language Result Execution time Memory
969165 2024-04-24T15:52:44 Z rahidilbayramli Martian DNA (BOI18_dna) C++17
100 / 100
381 ms 28180 KB
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define p_b pop_back
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
void solve()
{
    ll n, k, r, i;
    cin >> n >> k >> r;
    ll ans = LLONG_MAX;
    map<ll, ll>mp, mp2;
    vl v(n+5);
    for(i = 1; i <= n; i++)
        cin >> v[i];
    for(i = 0; i < r; i++)
    {
        ll b, q;
        cin >> b >> q;
        mp[b] = q;
    }
    ll f = n - r, j = 1;
    for(i = 1; i <= n; i++)
    {
        mp2[v[i]]++;
        if(mp2[v[i]] == mp[v[i]])
            f++;
        if(f < n)
            continue;
        while(mp2[v[j]] != mp[v[j]])
        {
            mp2[v[j]]--;
            j++;
        }
        ans = min(ans, i - j + 1);
    }
    if(ans == LLONG_MAX)
        cout << "impossible\n";
    else
        cout << ans << "\n";
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 452 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 2396 KB Output is correct
2 Correct 12 ms 2396 KB Output is correct
3 Correct 19 ms 2392 KB Output is correct
4 Correct 16 ms 2396 KB Output is correct
5 Correct 151 ms 13016 KB Output is correct
6 Correct 14 ms 2396 KB Output is correct
7 Correct 22 ms 2396 KB Output is correct
8 Correct 312 ms 28180 KB Output is correct
9 Correct 97 ms 3816 KB Output is correct
10 Correct 19 ms 2396 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 2 ms 600 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 456 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 360 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 202 ms 13692 KB Output is correct
2 Correct 172 ms 11092 KB Output is correct
3 Correct 159 ms 10772 KB Output is correct
4 Correct 11 ms 2396 KB Output is correct
5 Correct 170 ms 16452 KB Output is correct
6 Correct 381 ms 26552 KB Output is correct
7 Correct 81 ms 3940 KB Output is correct
8 Correct 119 ms 5632 KB Output is correct
9 Correct 14 ms 2396 KB Output is correct
10 Correct 12 ms 2256 KB Output is correct
11 Correct 19 ms 2404 KB Output is correct
12 Correct 17 ms 2396 KB Output is correct
13 Correct 147 ms 13016 KB Output is correct
14 Correct 14 ms 2396 KB Output is correct
15 Correct 22 ms 2396 KB Output is correct
16 Correct 266 ms 28140 KB Output is correct
17 Correct 95 ms 3932 KB Output is correct
18 Correct 18 ms 2396 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 504 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 3 ms 860 KB Output is correct
23 Correct 2 ms 600 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct