답안 #388820

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
388820 2021-04-13T05:09:01 Z Nordway Martian DNA (BOI18_dna) C++17
100 / 100
39 ms 4512 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

const int N=2e5+500;
const int M=1e6+1;
const ll inf=2e9+11;
const ld EPS=1e-6;
const int INF=1e9;
const ll mod=998244353/*1e9+7*/;
const int dx[4]={1,0,0,-1};
const int dy[4]={0,1,-1,0};

int a[N],b[N],c[N];

void solve(){
  int n,k,m;
  cin>>n>>k>>m;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  for(int i=0;i<k;i++){
    b[i]=-inf;
  }
  for(int i=1;i<=m;i++){
    int x,y;
    cin>>x>>y;
    b[x]=y;
  }
  int l=1;
  int cnt=0;
  int ans=inf;
  for(int r=1;r<=n;r++){
    c[a[r]]++;
    if(c[a[r]]==b[a[r]])cnt++;
    while(c[a[l]]>b[a[l]]){
      c[a[l]]--;
      l++;
    }
    if(cnt==m)ans=min(ans,r-l+1);
  }
  if(ans==inf)cout<<"impossible";
  else cout<<ans;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  int T=1;
  //cin>>T;
  for(int i=1;i<=T;i++){
    solve();
    cout<<nl;
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 1484 KB Output is correct
2 Correct 16 ms 1484 KB Output is correct
3 Correct 16 ms 1484 KB Output is correct
4 Correct 20 ms 1484 KB Output is correct
5 Correct 24 ms 2832 KB Output is correct
6 Correct 17 ms 1516 KB Output is correct
7 Correct 15 ms 1612 KB Output is correct
8 Correct 30 ms 3844 KB Output is correct
9 Correct 18 ms 2124 KB Output is correct
10 Correct 14 ms 1396 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 276 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 324 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 3416 KB Output is correct
2 Correct 30 ms 3060 KB Output is correct
3 Correct 24 ms 2756 KB Output is correct
4 Correct 15 ms 1448 KB Output is correct
5 Correct 36 ms 4028 KB Output is correct
6 Correct 39 ms 4512 KB Output is correct
7 Correct 19 ms 2124 KB Output is correct
8 Correct 23 ms 2376 KB Output is correct
9 Correct 14 ms 1484 KB Output is correct
10 Correct 15 ms 1436 KB Output is correct
11 Correct 16 ms 1492 KB Output is correct
12 Correct 17 ms 1476 KB Output is correct
13 Correct 20 ms 2776 KB Output is correct
14 Correct 14 ms 1400 KB Output is correct
15 Correct 15 ms 1584 KB Output is correct
16 Correct 23 ms 3908 KB Output is correct
17 Correct 18 ms 2124 KB Output is correct
18 Correct 14 ms 1468 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct