답안 #945421

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
945421 2024-03-13T18:54:58 Z rahidilbayramli Martian DNA (BOI18_dna) C++17
0 / 100
155 ms 27916 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;
vl g[sz];
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];
        vl vect;
        for(i = 1; i <= r; i++){
            ll x, y;
            cin >> x >> y;
            mp[x] = y;
            vect.pb(x);
        }
        for(i = 1; i <= n; i++)
        {
            for(auto u : vect){
                grid[u][i] = grid[u][i-1];
                if(v[i] == u)
                    grid[u][i]++;
            }
        }
        for(i = 1; i <= n; i++)
        {
            ll l = i, r = n;
            while(l <= r)
            {
                ll mid = (l + r) / 2;
                bool possible = true;
                for(auto u : vect)
                {
                    ll x = grid[u][mid] - grid[u][i-1];
                    if(x < mp[u]){
                        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";
    }
}

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:29:24: warning: unused variable 'j' [-Wunused-variable]
   29 |         ll n, k, r, i, j, ans = LLONG_MAX;
      |                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Runtime error 6 ms 11612 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5900 KB Output is correct
2 Correct 2 ms 6236 KB Output is correct
3 Runtime error 6 ms 11608 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 23388 KB Output is correct
2 Correct 28 ms 10072 KB Output is correct
3 Correct 155 ms 24412 KB Output is correct
4 Correct 87 ms 24412 KB Output is correct
5 Runtime error 20 ms 15964 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 51 ms 27916 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -