이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
const int N = 2e5;
int n, k, q;
vector<int> a;
vector<pair<int, int> > query;
int nuk[N+10], need[N + 10];
main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> k >> q;
a.resize(n);
for(int i = 0;i < n; i++){
cin >> a[i];
nuk[a[i]]++;
}
for(int i = 0;i < q; i++){
int c, cnt; cin >> c >> cnt;
query.push_back({c, cnt});
need[c] = cnt;
}
for(auto [c, cnt] : query){
if(nuk[c] < cnt){
cout << "impossible";
return 0;
}
}
for(int i = 0;i < n; i++) nuk[a[i]] = 0;
int ans = n, ok = 0;
for(int l = 0, r = 0; l < n; l++){
while(r < n && ok < q){
nuk[a[r]]++;
if(nuk[a[r]] == need[a[r]]){
ok++;
}
r++;
}
if(ok > q) assert(false);
if(ok == q){
ans = min(ans, r - l);
}
if(nuk[a[l]] == need[a[l]]){
ok--;
}
nuk[a[l]]--;
}
cout << ans;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
dna.cpp:16:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
16 | main(){
| ^~~~
# | 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... |