///huynhocute123///
#include<bits/stdc++.h>
using namespace std;
#define S second
#define F first
#define pii pair<int,int>
#define piii pair<int,pair<int,int>>
#define pb push_back
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define REP(i, a, b) for(int i = b; i >= a; --i)
#define ALL(v) v.begin(),v.end()
#define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
#define out(name) if(fopen(name, "w")) freopen(name, "w", stdout);
//random_device rd;
//mt19937 rng(rd());
//#pragma GCC optimize ("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("popcnt")
//#define int long long
const int maxN = 2 * 1e5 + 9 ;
const int modd = 1e9 + 7;
const int base = 2309;
const int MAX = 1e9+9;
const double pi = 3.14159265358979323846;
const double rad = 3.14159265358979323846 /180;
void minimize(int &u, int v){
if(v < u) u = v;
}
void maximize(int &u, int v){
if(v > u) u = v;
}
int n, k, t, m, res, a[maxN], mn[maxN], cnt[maxN];
int l, r;
bool vis[maxN];
vector<int> e[maxN];
void solve(){
cin >> n >> k >> m;
FOR(i, 1, n)cin >> a[i];
FOR(i, 1, m){
cin >> l >> r;
mn[l] =r;
}
int ck = 0;
FOR(i , 0 , k -1){
if(mn[i] ==0){
++ck;
}
}
// cout << ck << " ";
r = 0;
res =MAX;
FOR(i , 1, n){
while(r <= n && ck != k){
r++;
if(r > n)break;
++cnt[a[r]];
if(cnt[a[r]] == mn[a[r]])++ck;
}
if(r > n)break;
// cerr << i << " " << r << '\n';
minimize(res,r- i +1);
if(mn[a[i]] == cnt[a[i]])--ck;
cnt[a[i]]--;
}
if(res == MAX)cout << "impossible";
else cout << res;
}
signed main(){
// freopen("name.inp","r",stdin);
// freopen("name.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);
inp("task.inp");
// out("task.out");
int tc = 1;
// cin >> tc;
while( tc-- )solve();
cerr << '\n' << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << " s\n" ;
}
Compilation message
dna.cpp: In function 'int main()':
dna.cpp:12:47: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define inp(name) if(fopen(name, "r")) freopen(name, "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~
dna.cpp:75:5: note: in expansion of macro 'inp'
75 | inp("task.inp");
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
4944 KB |
Output is correct |
4 |
Correct |
3 ms |
4944 KB |
Output is correct |
5 |
Correct |
3 ms |
4944 KB |
Output is correct |
6 |
Correct |
2 ms |
6748 KB |
Output is correct |
7 |
Correct |
2 ms |
6736 KB |
Output is correct |
8 |
Correct |
2 ms |
6736 KB |
Output is correct |
9 |
Correct |
2 ms |
6736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6736 KB |
Output is correct |
2 |
Correct |
2 ms |
6756 KB |
Output is correct |
3 |
Correct |
2 ms |
6760 KB |
Output is correct |
4 |
Correct |
4 ms |
5200 KB |
Output is correct |
5 |
Correct |
4 ms |
5200 KB |
Output is correct |
6 |
Correct |
4 ms |
5200 KB |
Output is correct |
7 |
Correct |
6 ms |
4944 KB |
Output is correct |
8 |
Correct |
4 ms |
4944 KB |
Output is correct |
9 |
Correct |
4 ms |
5168 KB |
Output is correct |
10 |
Correct |
4 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
4944 KB |
Output is correct |
12 |
Correct |
4 ms |
4944 KB |
Output is correct |
13 |
Correct |
4 ms |
5088 KB |
Output is correct |
14 |
Correct |
4 ms |
4944 KB |
Output is correct |
15 |
Correct |
6 ms |
4944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
5968 KB |
Output is correct |
2 |
Correct |
13 ms |
5712 KB |
Output is correct |
3 |
Correct |
14 ms |
5712 KB |
Output is correct |
4 |
Correct |
12 ms |
5712 KB |
Output is correct |
5 |
Correct |
15 ms |
6396 KB |
Output is correct |
6 |
Correct |
11 ms |
5712 KB |
Output is correct |
7 |
Correct |
16 ms |
5712 KB |
Output is correct |
8 |
Correct |
17 ms |
6728 KB |
Output is correct |
9 |
Correct |
12 ms |
5968 KB |
Output is correct |
10 |
Correct |
9 ms |
7504 KB |
Output is correct |
11 |
Correct |
2 ms |
6736 KB |
Output is correct |
12 |
Correct |
2 ms |
6736 KB |
Output is correct |
13 |
Correct |
2 ms |
6736 KB |
Output is correct |
14 |
Correct |
2 ms |
6736 KB |
Output is correct |
15 |
Correct |
2 ms |
6736 KB |
Output is correct |
16 |
Correct |
2 ms |
6736 KB |
Output is correct |
17 |
Correct |
4 ms |
5060 KB |
Output is correct |
18 |
Correct |
4 ms |
4944 KB |
Output is correct |
19 |
Correct |
4 ms |
4944 KB |
Output is correct |
20 |
Correct |
3 ms |
5116 KB |
Output is correct |
21 |
Correct |
3 ms |
5120 KB |
Output is correct |
22 |
Correct |
3 ms |
4944 KB |
Output is correct |
23 |
Correct |
4 ms |
5112 KB |
Output is correct |
24 |
Correct |
3 ms |
4944 KB |
Output is correct |
25 |
Correct |
3 ms |
4944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
7504 KB |
Output is correct |
2 |
Correct |
20 ms |
6224 KB |
Output is correct |
3 |
Correct |
18 ms |
6268 KB |
Output is correct |
4 |
Correct |
11 ms |
5712 KB |
Output is correct |
5 |
Correct |
21 ms |
7572 KB |
Output is correct |
6 |
Correct |
24 ms |
7504 KB |
Output is correct |
7 |
Correct |
12 ms |
7504 KB |
Output is correct |
8 |
Correct |
15 ms |
7504 KB |
Output is correct |
9 |
Correct |
9 ms |
7504 KB |
Output is correct |
10 |
Correct |
10 ms |
7504 KB |
Output is correct |
11 |
Correct |
10 ms |
7504 KB |
Output is correct |
12 |
Correct |
10 ms |
7504 KB |
Output is correct |
13 |
Correct |
13 ms |
7536 KB |
Output is correct |
14 |
Correct |
9 ms |
7504 KB |
Output is correct |
15 |
Correct |
10 ms |
7504 KB |
Output is correct |
16 |
Correct |
15 ms |
7504 KB |
Output is correct |
17 |
Correct |
14 ms |
5968 KB |
Output is correct |
18 |
Correct |
11 ms |
5960 KB |
Output is correct |
19 |
Correct |
4 ms |
5200 KB |
Output is correct |
20 |
Correct |
2 ms |
5200 KB |
Output is correct |
21 |
Correct |
3 ms |
5200 KB |
Output is correct |
22 |
Correct |
2 ms |
5200 KB |
Output is correct |
23 |
Correct |
2 ms |
6736 KB |
Output is correct |
24 |
Correct |
4 ms |
4944 KB |
Output is correct |
25 |
Correct |
4 ms |
4944 KB |
Output is correct |
26 |
Correct |
4 ms |
4944 KB |
Output is correct |
27 |
Correct |
4 ms |
4944 KB |
Output is correct |
28 |
Correct |
4 ms |
4944 KB |
Output is correct |
29 |
Correct |
4 ms |
4944 KB |
Output is correct |
30 |
Correct |
4 ms |
4944 KB |
Output is correct |
31 |
Correct |
4 ms |
4944 KB |
Output is correct |
32 |
Correct |
4 ms |
4944 KB |
Output is correct |
33 |
Correct |
4 ms |
4944 KB |
Output is correct |