# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1127481 | MinhTuan11 | Martian DNA (BOI18_dna) | C++20 | 32 ms | 4936 KiB |
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
const int N = 2e5 + 5;
const int K = 1e2 + 5;
const int mod = 1e9 + 7;
const int inf = 1e18 + 7;
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
using namespace std;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int n, k, r, a[N];
int b[N], c[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
if(ifstream("file.inp")){
freopen("file.inp", "r", stdin);
freopen("file.out", "w", stdout);
}
cin >> n >> k >> r;
for(int i = 1; i <= n; i++) cin >> a[i];
memset(b, -1, sizeof b);
for(int i = 1, x, y; i <= r; i++) {
cin >> x >> y;
b[x] = y;
}
int j = 1, com = 0, res = n + 1;
for(int i = 1; i <= n; i++) {
c[a[i]]++;
if(c[a[i]] == b[a[i]] && b[a[i]] != -1) com++;
while(c[a[j]] > b[a[j]] || b[a[j]] == -1) c[a[j++]]--;
if(com == r) {
res = min(res, i - j + 1);
}
}
if(res == n + 1) cout << "impossible";
else cout << res << '\n';
return 0;
}
// tuntun
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |