답안 #1010375

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1010375 2024-06-29T02:31:37 Z uyt777443 Martian DNA (BOI18_dna) C++17
0 / 100
209 ms 14268 KB
#include <iostream>
#include <iomanip>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <utility>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <random>
#include <sstream>
#include <string.h>
#include <assert.h>
#include <limits.h>
using namespace std;

#define fi first
#define se second
#define int long long
#define pb push_back

typedef pair<int,int> ii;

const int INF = 1e18;

map<int, int> cons;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k, r; cin >> n >> k >> r;
	vector<int> a(n + 2); for (int i=1; i<=n; i++) cin >> a[i];
	for (int i=1; i<=r; i++) {
		int b, q; cin >> b >> q;
		cons[b] = q;
	} 
	// cout << "HERE\n";

	queue<int> rem_until, cur;
	int cnt = 0; int ans = INF;
	map<int, int> have;
	for (int i=1; i<=n; i++) {
		// cout << ">> " << a[i] << " " << have[a[i]] << " " << cons[a[i]] << '\n';
		if (cons.count(a[i]) && have[a[i]] < cons[a[i]]) {
			cur.push(a[i]), have[a[i]]++; if (have[a[i]] == cons[a[i]]) cnt++;
		}
		else {
			have[a[i]]++; cur.push(a[i]); 
			if (cur.front() == a[i])
				cur.pop();
			else  
				rem_until.push(a[i]);
			
		}
		if (cnt == r)
			ans = min(ans, (int)cur.size());
		while(!cur.empty() && !rem_until.empty() && cur.front() == rem_until.front()) {
			cur.pop(), rem_until.pop();
		}
	}
	if (ans == INF) cout << "impossible";
	else cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 3164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 209 ms 14268 KB Output isn't correct
2 Halted 0 ms 0 KB -