답안 #931329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931329 2024-02-21T15:29:33 Z vjudge1 Martian DNA (BOI18_dna) C++17
100 / 100
210 ms 17760 KB
/*
                              _,add8ba,
                            ,d888888888b,
                           d8888888888888b                        _,ad8ba,_
                          d888888888888888)                     ,d888888888b,
                          I8888888888888888 _________          ,8888888888888b
                __________`Y88888888888888P"""""""""""baaa,__ ,888888888888888,
            ,adP"""""""""""9888888888P""^                 ^""Y8888888888888888I
         ,a8"^           ,d888P"888P^                           ^"Y8888888888P'
       ,a8^            ,d8888'                                     ^Y8888888P'
      a88'           ,d8888P'                                        I88P"^
    ,d88'           d88888P'                                          "b,
   ,d88'           d888888'                                            `b,
  ,d88'           d888888I                                              `b,
  d88I           ,8888888'            ___                                `b,
 ,888'           d8888888          ,d88888b,              ____            `b,
 d888           ,8888888I         d88888888b,           ,d8888b,           `b
,8888           I8888888I        d8888888888I          ,88888888b           8,
I8888           88888888b       d88888888888'          8888888888b          8I
d8886           888888888       Y888888888P'           Y8888888888,        ,8b
88888b          I88888888b      `Y8888888^             `Y888888888I        d88,
Y88888b         `888888888b,      `""""^                `Y8888888P'       d888I
`888888b         88888888888b,                           `Y8888P^        d88888
 Y888888b       ,8888888888888ba,_          _______        `""^        ,d888888
 I8888888b,    ,888888888888888888ba,_     d88888888b               ,ad8888888I
 `888888888b,  I8888888888888888888888b,    ^"Y888Y"^      ____.,ad88888888888I
  88888888888b,`888888888888888888888888b,     ""      ad888888888888888888888'
  8888888888888698888888888888888888888888b_,ad88ba,_,d88888888888888888888888
  88888888888888888888888888888888888888888b,`""""" d8888888888888888888888888I
  8888888888888888888888888888888888888888888baaad888888888888888888888888888'
  Y8888888888888888888888888888888888888888888888888888888888888888888888888P
  I888888888888888888888888888888888888888888888P^  ^Y8888888888888888888888'
  `Y88888888888888888P88888888888888888888888888'     ^88888888888888888888I
   `Y8888888888888888 `8888888888888888888888888       8888888888888888888P'
    `Y888888888888888  `888888888888888888888888,     ,888888888888888888P'
     `Y88888888888888b  `88888888888888888888888I     I888888888888888888'
       "Y8888888888888b  `8888888888888888888888I     I88888888888888888'
         "Y88888888888P   `888888888888888888888b     d8888888888888888'
            ^""""""""^     `Y88888888888888888888,    888888888888888P'
                             "8888888888888888888b,   Y888888888888P^
                              `Y888888888888888888b   `Y8888888P"^
                                "Y8888888888888888P     `""""^
                                  `"YY88888888888P'
                                       ^""""""""'
*Allah is watching me :) * 
*/
 
#include<bits/stdc++.h>
#define ll            long long	
#define yes           "YES\n"
#define no            "NO\n"
#define all(v)        v.begin(), v.end()
#define pb            push_back
#define F             first
#define S             second
#define mk            make_pair
#define skip          continue;
#define ld            long double
using namespace std;
const int e=1e9+11;	
const int L=1e7+11;
const int N=2e5+11;
const ll inf=1e18;
const int mod=1e9+7;
void solve(){
	int n,k,d;
	cin>>n>>k>>d;
	int a[n+1];
	for(int i=1; i<=n; i++){
		cin>>a[i];
	}
	map<int,int>mp,had;
	int ans=INT_MAX;
	for(int i=1; i<=d; i++){
		int u,v;
		cin>>u>>v;
		had[u]=1;
		mp[u]=v;
	}
	int l=1,r=1,c=d;
	while(r<=n){
		int v=a[r];
		mp[v]--;
		if(mp[v]==0){
			c--;
			if(c==0){
				while((mp[a[l]]+1<=0 || !had[a[l]]) && l<=r){
					if(had[a[l]]){
						mp[a[l]]++;
					}
					l++;
				}
				ans=min(ans,r-l+1);
				mp[a[l]]++;
				if(mp[a[l]]>0){
					c++;
				}
				l++;
			}
		}
		r++;
	}
	if(ans==INT_MAX){
		cout<<"impossible"<<endl;
		return;
	}
	cout<<ans<<endl;

}
int main(){
ios_base::sync_with_stdio(0); 
cin.tie(0); 
cout.tie(0);
//freopen("sum2.in", "r", stdin);
//freopen("sum2.out", "w", stdout);
int tt=1,time=1;
// cin>>tt;
while(tt--){
    solve();
}
}

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:116:10: warning: unused variable 'time' [-Wunused-variable]
  116 | int tt=1,time=1;
      |          ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1112 KB Output is correct
2 Correct 11 ms 1112 KB Output is correct
3 Correct 16 ms 1116 KB Output is correct
4 Correct 13 ms 1112 KB Output is correct
5 Correct 106 ms 8684 KB Output is correct
6 Correct 12 ms 1116 KB Output is correct
7 Correct 17 ms 1236 KB Output is correct
8 Correct 173 ms 15428 KB Output is correct
9 Correct 67 ms 1952 KB Output is correct
10 Correct 16 ms 1112 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 632 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 8712 KB Output is correct
2 Correct 127 ms 6740 KB Output is correct
3 Correct 105 ms 6636 KB Output is correct
4 Correct 10 ms 1116 KB Output is correct
5 Correct 111 ms 9572 KB Output is correct
6 Correct 210 ms 17760 KB Output is correct
7 Correct 50 ms 2384 KB Output is correct
8 Correct 79 ms 3072 KB Output is correct
9 Correct 12 ms 1116 KB Output is correct
10 Correct 10 ms 1116 KB Output is correct
11 Correct 15 ms 1112 KB Output is correct
12 Correct 13 ms 1116 KB Output is correct
13 Correct 106 ms 8560 KB Output is correct
14 Correct 12 ms 1116 KB Output is correct
15 Correct 19 ms 1236 KB Output is correct
16 Correct 168 ms 15440 KB Output is correct
17 Correct 64 ms 1876 KB Output is correct
18 Correct 16 ms 1112 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 376 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct