답안 #1083358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083358 2024-09-03T02:52:37 Z XecovZ Martian DNA (BOI18_dna) C++17
100 / 100
664 ms 50144 KB
#include <bits/stdc++.h>
typedef long double ld;
#define int long long
#define TC int t; cin >> t; for(int _=1; _<=t; _++)
#define bismillah ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
using namespace std;

const int N = 2e5+7, INF = 1e18;

int a[N];
int n, k, q;
map<int, int> mapp, frq;

signed main(){
   bismillah;
   cin >> n >> k >> q;
   for(int i=1; i<=n; i++){
      cin >> a[i];
      frq[a[i]]++;
      mapp[a[i]] = INF;
   }

   int done = k;
   while(q--){
      int x, c; cin >> x >> c;
      mapp[x] = c; done--;

      if(frq[x]<c){
         cout << "impossible";
         return 0;
      }
   }

   map<int, int> now;
   map<int, bool> flag;
   int ans = n;
   int l = 1; // l==r allowed

   // find prefix first
   int st = 1;
   for(int i=1; i<=n; i++){
      now[a[i]]++;
      if(now[a[i]]>=mapp[a[i]] && !flag[a[i]]){
         done++;
         flag[a[i]] = 1;
      }

      if(done==k){
         ans = min(ans, i);
         st = i;
         break;
      }
   }

   int r;
   for(r=st; r<=n; r++){
      if(r>st){
         now[a[r]]++;
         if(now[a[r]]>=mapp[a[r]] && !flag[a[r]]){
            done++;
            flag[a[r]] = 1;
         }

         now[a[l]]--;
         if(now[a[l]]<mapp[a[l]] && flag[a[l]]){
            done--;
            flag[a[l]] = 0;
         }l++;
      }

      if(done==k){
         while(l<r && (now[a[l]]>mapp[a[l]] || !flag[a[l]])){
            now[a[l]]--;
            l++;
         }
         ans = min(ans, r-l+1);
         /* cout << l << " " << r << '\n';
         break; */
      }
   }
   

   cout << ans;
}
/* 
18 4 3
0 3 0 1 3 1 2 0 0 1 1 2 0 0 1 3 1 2
0 2
1 2
2 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 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 3 ms 860 KB Output is correct
4 Correct 5 ms 1372 KB Output is correct
5 Correct 3 ms 860 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 468 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 2392 KB Output is correct
2 Correct 13 ms 2172 KB Output is correct
3 Correct 18 ms 2344 KB Output is correct
4 Correct 15 ms 2396 KB Output is correct
5 Correct 306 ms 23064 KB Output is correct
6 Correct 15 ms 2396 KB Output is correct
7 Correct 16 ms 2396 KB Output is correct
8 Correct 575 ms 50000 KB Output is correct
9 Correct 184 ms 4956 KB Output is correct
10 Correct 20 ms 2396 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 5 ms 1372 KB Output is correct
15 Correct 3 ms 860 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 348 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 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 357 ms 23664 KB Output is correct
2 Correct 323 ms 18388 KB Output is correct
3 Correct 291 ms 18308 KB Output is correct
4 Correct 12 ms 2392 KB Output is correct
5 Correct 105 ms 15680 KB Output is correct
6 Correct 664 ms 48992 KB Output is correct
7 Correct 154 ms 4944 KB Output is correct
8 Correct 240 ms 8156 KB Output is correct
9 Correct 14 ms 2392 KB Output is correct
10 Correct 12 ms 2396 KB Output is correct
11 Correct 17 ms 2460 KB Output is correct
12 Correct 15 ms 2396 KB Output is correct
13 Correct 306 ms 23124 KB Output is correct
14 Correct 14 ms 2396 KB Output is correct
15 Correct 16 ms 2396 KB Output is correct
16 Correct 614 ms 50144 KB Output is correct
17 Correct 182 ms 5204 KB Output is correct
18 Correct 18 ms 2416 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 3 ms 860 KB Output is correct
22 Correct 4 ms 1372 KB Output is correct
23 Correct 4 ms 860 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 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct