답안 #730285

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730285 2023-04-25T15:03:01 Z Karpin Martian DNA (BOI18_dna) C++17
100 / 100
35 ms 5380 KB
#include <bits/stdc++.h>

using namespace std;


#define ll long long
#define vt vector
#define ar array

int neededAmounts[200005];
int totalAmounts[200005];
int curAmount[200005];

bool needed [200005];

int totalNucles = 0;
int n;




void solve(){

    int k, r;
    cin >> n >> k >> r;
    vt<int> nucles (n);

    for(int i = 0; i < n; i++){
        cin >> nucles[i];
        totalAmounts[nucles[i]]++;
    }

    

    for(int i = 0; i < r; i++){
        int a, b;
        cin >> a >> b;
        if (totalAmounts[a] < b){
            cout << "impossible" << endl;
            return;            
        }
        neededAmounts[a] = b;
        totalNucles += b;
        needed[a] = true;
    }


    int left = 0;
    int right = -1;
    int res = n;

    while (r > 0){
        if (curAmount[nucles[right + 1]] + 1 == neededAmounts[nucles[right + 1]]){
            curAmount[nucles[right + 1]]++;
            r--;
            right++;
        }else{
            curAmount[nucles[right + 1]]++;
            right++;
        }
    }
    res = right - left + 1;

    while (right < n){
        if (curAmount[nucles[left]] > neededAmounts[nucles[left]]){
            curAmount[nucles[left]]--;
            left++;
            res = min(res, right - left + 1);
            continue;
        }
        curAmount[nucles[right + 1]]++;
        right++;
    }

    cout << res << endl;


		

}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int testcases = 1;

	// cin >> testcases;

	while(testcases--){
		solve();
	}

	return 0;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1108 KB Output is correct
2 Correct 11 ms 1500 KB Output is correct
3 Correct 13 ms 1492 KB Output is correct
4 Correct 12 ms 1500 KB Output is correct
5 Correct 17 ms 2952 KB Output is correct
6 Correct 11 ms 1492 KB Output is correct
7 Correct 12 ms 1620 KB Output is correct
8 Correct 20 ms 3924 KB Output is correct
9 Correct 16 ms 2176 KB Output is correct
10 Correct 12 ms 1492 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 376 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 2084 KB Output is correct
2 Correct 23 ms 3400 KB Output is correct
3 Correct 20 ms 3128 KB Output is correct
4 Correct 12 ms 1488 KB Output is correct
5 Correct 17 ms 2780 KB Output is correct
6 Correct 35 ms 5380 KB Output is correct
7 Correct 16 ms 2172 KB Output is correct
8 Correct 18 ms 2512 KB Output is correct
9 Correct 13 ms 1492 KB Output is correct
10 Correct 12 ms 1524 KB Output is correct
11 Correct 13 ms 1492 KB Output is correct
12 Correct 11 ms 1556 KB Output is correct
13 Correct 17 ms 2956 KB Output is correct
14 Correct 11 ms 1492 KB Output is correct
15 Correct 14 ms 1620 KB Output is correct
16 Correct 21 ms 3924 KB Output is correct
17 Correct 15 ms 2180 KB Output is correct
18 Correct 12 ms 1508 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 328 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 324 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
33 Correct 0 ms 324 KB Output is correct