| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1298573 | dzhoz0 | Martian DNA (BOI18_dna) | C++20 | 19 ms | 3080 KiB |
/*
it could have been better :)
it will next time ;)
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e18
#define f first
#define s second
#define pii pair<int, int>
#define vi vector<int>
const int MOD = 1'000'000'000 + 7;
void setIO(string name = "")
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#ifdef LOCAL
freopen("inp.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#else
if (!name.empty())
{
freopen((name + ".INP").c_str(), "r", stdin);
freopen((name + ".OUT").c_str(), "w", stdout);
}
#endif
}
const int MAXN = 2e5;
int n, k, q;
int a[MAXN + 5];
int req[MAXN + 5];
int cnt[MAXN + 5];
void solve()
{
cin >> n >> k >> q;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 0; i <= k; i++) req[i] = INF;
for(int i = 1; i <= q; i++) {
int b; cin >> b;
cin >> req[b];
}
int ok = 0;
int l = 1, r = 1;
while(r <= n) {
cnt[a[r]]++;
if(cnt[a[r]] == req[a[r]]) ok++;
if(ok == q) break;
r++;
}
if(r == n + 1) {
cout << "impossible\n";
return;
}
int res = INF;
while(r <= n) {
cnt[a[r]]++;
if(cnt[a[r]] == req[a[r]]) ok++;
while(l <= r) {
cnt[a[l]]--;
if(cnt[a[l]] == req[a[l]] - 1) ok--;
if(ok == q) l++;
else {
cnt[a[l]]++;
if(cnt[a[l]] == req[a[l]] - 1) ok--;
break;
}
}
res = min(res, r - l + 1);
r++;
}
cout << res << '\n';
}
signed main()
{
setIO();
int t = 1;
// cin >> t;
while (t--)
solve();
}
컴파일 시 표준 에러 (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... | ||||
