Submission #946566

# Submission time Handle Problem Language Result Execution time Memory
946566 2024-03-14T18:47:14 Z rahidilbayramli Martian DNA (BOI18_dna) C++17
0 / 100
151 ms 59476 KB
#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 pb push_back
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll sz = 2e5+5;
ll grid[15][sz];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tests = 1;
    //cin >> tests;
    while(tests--)
    {
        ll n, k, r, i, j, ans = LLONG_MAX;
        cin >> n >> k >> r;
        vl v(n+5);
        map<ll, ll>mp;
        for(i = 1; i <= n; i++)
            cin >> v[i];
        ll f[r+5];
        for(i = 1; i <= r; i++){
            ll x, y;
            cin >> x >> y;
            mp[x] = y;
            f[i] = x;
        }
        for(i = 1; i <= r; i++){
            for(j = 1; j <= n; j++)
            {
                grid[i][j] = grid[i][j-1];
                if(f[i] == v[j])
                    grid[i][j]++;
            }
        }
        for(i = 1; i <= n; i++)
        {
            ll l = i, r = n;
            while(l <= r)
            {
                ll mid = (l + r) / 2;
                bool possible = true;
                for(j = 1; j <= r; j++)
                {
                    ll x = grid[j][mid] - grid[j][i-1];
                    if(x < mp[f[j]]){
                        possible = false;
                        break;
                    }
                }
                if(possible)
                {
                    ans = min(ans, mid - i + 1);
                    r = mid - 1;
                }
                else
                    l = mid + 1;
            }
        }
        if(ans == LLONG_MAX)
            cout << "impossible\n";
        else
            cout << ans << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 151 ms 17148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 71 ms 59476 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -