답안 #933252

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
933252 2024-02-25T10:14:51 Z LucaIlie Martian DNA (BOI18_dna) C++17
40 / 100
2000 ms 2644 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2e5;
const int MAX_K = MAX_N;

int v[MAX_N], f[MAX_K], q[MAX_K];

int cond;

void add( int i ) {
    f[v[i]]++;
    if ( f[v[i]] == q[v[i]] )
        cond++;
}

void rem( int i ) {
    if ( f[v[i]] == q[v[i]] )
        cond--;
    f[v[i]]--;
}

int main() {
    int n, k, m;

    cin >> n >> k >> m;
    for ( int i = 0; i < n; i++ )
        cin >> v[i];
    for ( int i = 0; i < m; i++ ) {
        int b;
        cin >> b;
        cin >> q[b];
    }

    /*cond = k - m;
    int l = 0, minLen = n + 1;
    for ( int r = 0; r < n; r++ ) {
        add( r );
        while ( cond >= k && l <= r ) {
            rem( l );
            l++;
        }
        if ( l > 0 ) {
            l--;
            add( l );
        }
        if ( cond >= k )
            minLen = min( minLen, r - l + 1 );
    }*/

    cond = k - m;
    int minLen = n + 1;
    for ( int l = 0; l < n; l++ ) {
        for ( int r = l; r < n; r++ ) {
            add( r );
            if ( cond == k )
                minLen = min( minLen, r - l + 1 );
        }
        for ( int r = l; r < n; r++ )
            rem( r );
    }

    if ( minLen == n + 1 )
        cout << "impossible\n";
    else
        cout << minLen << "\n";

    return 0;
}
# 결과 실행 시간 메모리 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 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2492 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2396 KB Output is correct
2 Correct 16 ms 2488 KB Output is correct
3 Correct 19 ms 2500 KB Output is correct
4 Correct 18 ms 2396 KB Output is correct
5 Correct 17 ms 2396 KB Output is correct
6 Correct 20 ms 2552 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2496 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2051 ms 2396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2098 ms 2644 KB Time limit exceeded
2 Halted 0 ms 0 KB -