답안 #927163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927163 2024-02-14T10:47:37 Z vjudge1 Martian DNA (BOI18_dna) C++17
100 / 100
27 ms 5212 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lld long double
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define IShowSpeed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=2e5+10;
const int K=200;
const int mod=1e9+7;
const ll inf=1e18+228;
const int dx[]={-1,0,0,1};
const int dy[]={0,-1,1,0};
ll h[N],cnt[N],n,k,r,lol=0,ans=inf;
deque<ll>v;

int main()
{
	IShowSpeed
	cin>>n>>k>>r;
	for(int i=1;i<=n;i++) cin>>h[i],cnt[i]=-inf;
	for(int i=1;i<=r;i++)
	{
		ll x,y;
		cin>>x>>y;
		if(cnt[x]==-inf) cnt[x]=y;
		else cnt[x]+=y;
	}

	for(int i=1;i<=n;i++)
	{
		if(cnt[h[i]]==-inf) continue;
		v.pb(i);
		cnt[h[i]]--;
		if(!cnt[h[i]]) lol++;
		while(cnt[h[v.front()]]<0)
		{
			cnt[h[v.front()]]++;
			v.pop_front();
		}
		if(lol==r) ans=min(v.back()-v.front()+1,ans);
	}
	if(ans==inf) cout<<"impossible";
	else cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 0 ms 2652 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 4188 KB Output is correct
2 Correct 10 ms 3728 KB Output is correct
3 Correct 10 ms 3388 KB Output is correct
4 Correct 10 ms 4188 KB Output is correct
5 Correct 15 ms 3420 KB Output is correct
6 Correct 13 ms 5152 KB Output is correct
7 Correct 9 ms 3676 KB Output is correct
8 Correct 15 ms 3420 KB Output is correct
9 Correct 11 ms 3400 KB Output is correct
10 Correct 10 ms 4188 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2440 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 4188 KB Output is correct
2 Correct 24 ms 3928 KB Output is correct
3 Correct 15 ms 3676 KB Output is correct
4 Correct 9 ms 3416 KB Output is correct
5 Correct 22 ms 4700 KB Output is correct
6 Correct 27 ms 4356 KB Output is correct
7 Correct 14 ms 4956 KB Output is correct
8 Correct 18 ms 4440 KB Output is correct
9 Correct 9 ms 4184 KB Output is correct
10 Correct 10 ms 3672 KB Output is correct
11 Correct 10 ms 3420 KB Output is correct
12 Correct 14 ms 3928 KB Output is correct
13 Correct 12 ms 3416 KB Output is correct
14 Correct 10 ms 5212 KB Output is correct
15 Correct 9 ms 3720 KB Output is correct
16 Correct 13 ms 3420 KB Output is correct
17 Correct 11 ms 3420 KB Output is correct
18 Correct 10 ms 3988 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 0 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct