Submission #643451

# Submission time Handle Problem Language Result Execution time Memory
643451 2022-09-22T04:19:48 Z kith14 Martian DNA (BOI18_dna) C++14
100 / 100
54 ms 6348 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define db double
#define pairll pair<ll,ll>
#define lpairll pair<ll,pairll>

#define repp(i,a,b) for (ll i = a; i <= b; i++)
#define repz(i,a,b) for (ll i = a; i < b; i++)
#define repm(i,a,b) for (ll i = a; i >= b; i--)
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

const ll N = 2e5+5, MOD = 1e9+7;
ll tc = 1, n, m, ar[N], br[N], need[N], cr[N], cnt[N];
ll x, y, k;
string s, s1, s2, ye = "YES", no = "NO";
vector<pairll> v;

bool pos(ll key){
  ll rem = k;
  memset(cnt,0,sizeof(cnt));
  repp(i,1,key){
    cnt[ar[i]]++;
    if (cnt[ar[i]] == need[ar[i]]) rem--;
    if (rem == 0) return 1;
  }
  repp(i,key+1,n){
    cnt[ar[i-key]]--;
    if (cnt[ar[i-key]] == need[ar[i-key]]-1) rem++;
    cnt[ar[i]]++;
    if (cnt[ar[i]] == need[ar[i]]) rem--;
    if (rem == 0) return 1;
  }
  return 0;
}

void input(){
  cin >> n >> m >> k;
  repp(i,1,n) cin >> ar[i];
  repp(i,1,k){
    cin >> x >> y;
    br[i] = x, cr[i] = y;
    need[x] = y;
  }
}

void solve(){
  ll l = 1, r = n, ret = -1;
  while(l <= r){
    ll md = (l+r)/2;
    if (pos(md)){
      r = md-1;
      ret = md;
    }
    else l = md+1;
  }
  if (ret == -1) cout << "impossible\n";
  else cout << ret << "\n";
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  //cin >> tc;
  while(tc--){
    input();
    solve();
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 2 ms 1800 KB Output is correct
3 Correct 1 ms 1888 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 1 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1876 KB Output is correct
2 Correct 2 ms 1876 KB Output is correct
3 Correct 2 ms 1876 KB Output is correct
4 Correct 2 ms 1964 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
6 Correct 2 ms 1876 KB Output is correct
7 Correct 1 ms 1876 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 1 ms 1876 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1880 KB Output is correct
12 Correct 1 ms 1876 KB Output is correct
13 Correct 1 ms 1876 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 1 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 3452 KB Output is correct
2 Correct 25 ms 3412 KB Output is correct
3 Correct 14 ms 3360 KB Output is correct
4 Correct 22 ms 3476 KB Output is correct
5 Correct 31 ms 3488 KB Output is correct
6 Correct 20 ms 3428 KB Output is correct
7 Correct 21 ms 3476 KB Output is correct
8 Correct 36 ms 3492 KB Output is correct
9 Correct 25 ms 3500 KB Output is correct
10 Correct 23 ms 3412 KB Output is correct
11 Correct 2 ms 1876 KB Output is correct
12 Correct 2 ms 1876 KB Output is correct
13 Correct 2 ms 1876 KB Output is correct
14 Correct 2 ms 1876 KB Output is correct
15 Correct 2 ms 1876 KB Output is correct
16 Correct 2 ms 1876 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 2 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 1 ms 1876 KB Output is correct
23 Correct 1 ms 1876 KB Output is correct
24 Correct 1 ms 1876 KB Output is correct
25 Correct 2 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 5328 KB Output is correct
2 Correct 46 ms 4860 KB Output is correct
3 Correct 43 ms 4232 KB Output is correct
4 Correct 10 ms 3412 KB Output is correct
5 Correct 41 ms 5436 KB Output is correct
6 Correct 54 ms 6348 KB Output is correct
7 Correct 28 ms 3644 KB Output is correct
8 Correct 39 ms 3848 KB Output is correct
9 Correct 25 ms 3412 KB Output is correct
10 Correct 22 ms 3412 KB Output is correct
11 Correct 15 ms 3376 KB Output is correct
12 Correct 20 ms 3476 KB Output is correct
13 Correct 29 ms 3496 KB Output is correct
14 Correct 20 ms 3412 KB Output is correct
15 Correct 21 ms 3368 KB Output is correct
16 Correct 34 ms 3412 KB Output is correct
17 Correct 25 ms 3440 KB Output is correct
18 Correct 25 ms 3476 KB Output is correct
19 Correct 2 ms 1876 KB Output is correct
20 Correct 2 ms 1828 KB Output is correct
21 Correct 2 ms 1876 KB Output is correct
22 Correct 2 ms 1876 KB Output is correct
23 Correct 3 ms 1920 KB Output is correct
24 Correct 2 ms 1876 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
26 Correct 2 ms 1876 KB Output is correct
27 Correct 1 ms 1876 KB Output is correct
28 Correct 1 ms 1876 KB Output is correct
29 Correct 1 ms 1876 KB Output is correct
30 Correct 1 ms 1876 KB Output is correct
31 Correct 1 ms 1876 KB Output is correct
32 Correct 1 ms 1876 KB Output is correct
33 Correct 1 ms 1876 KB Output is correct