답안 #1111282

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111282 2024-11-12T01:38:25 Z thangdz2k7 Martian DNA (BOI18_dna) C++17
100 / 100
25 ms 2640 KB
// author : thembululquaUwU
// 3.9.2024

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;

const int MaxN = 2e5;
const int mod = 1e9 + 7;

void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}

void solve(){
    int n, k, r; cin >> n >> k >> r;
    vector <int> d(n);
    for (int &f : d) cin >> f;
    vector <int> needs(k, 0);
    while (r --){
        int B, Q; cin >> B >> Q;
        needs[B] = Q;
    }

    int numok = 0;
    vector <int> cnt(k, 0);
    for (int i = 0; i < k; ++ i) numok += (cnt[i] >= needs[i]);

    auto update = [&](int type, int val) -> void {
        numok -= (cnt[type] >= needs[type]);
        cnt[type] += val;
        numok += (cnt[type] >= needs[type]);
    };

    r = 0; int ans = mod;
    for (int l = 0; l < n; ++ l){
        while (numok < k && r < n) update(d[r ++], 1);
        if (numok == k) minl(ans, r - l);
        update(d[l], -1);
    }

    if (ans < mod) cout << ans;
    else cout << "impossible";
}

int main(){
    if (fopen("dna.inp", "r")){
        freopen("dna.inp", "r", stdin);
        freopen("dna.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1; // cin >> t;
    while (t --) solve();
    return 0;
}

Compilation message

dna.cpp:18:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |           ^~~~
dna.cpp:18:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void maxl(auto &a, auto b) {a = max(a, b);}
      |                    ^~~~
dna.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |           ^~~~
dna.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void minl(auto &a, auto b) {a = min(a, b);}
      |                    ^~~~
dna.cpp: In function 'int main()':
dna.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen("dna.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
dna.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen("dna.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 508 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 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 336 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1104 KB Output is correct
2 Correct 11 ms 1104 KB Output is correct
3 Correct 10 ms 1104 KB Output is correct
4 Correct 9 ms 1104 KB Output is correct
5 Correct 13 ms 1880 KB Output is correct
6 Correct 8 ms 1104 KB Output is correct
7 Correct 9 ms 1104 KB Output is correct
8 Correct 15 ms 2640 KB Output is correct
9 Correct 10 ms 1104 KB Output is correct
10 Correct 9 ms 1104 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 508 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 2040 KB Output is correct
2 Correct 18 ms 1480 KB Output is correct
3 Correct 16 ms 1616 KB Output is correct
4 Correct 10 ms 1104 KB Output is correct
5 Correct 21 ms 1872 KB Output is correct
6 Correct 25 ms 2640 KB Output is correct
7 Correct 12 ms 1104 KB Output is correct
8 Correct 15 ms 1332 KB Output is correct
9 Correct 9 ms 1276 KB Output is correct
10 Correct 10 ms 1104 KB Output is correct
11 Correct 10 ms 1104 KB Output is correct
12 Correct 10 ms 1104 KB Output is correct
13 Correct 14 ms 1872 KB Output is correct
14 Correct 9 ms 1104 KB Output is correct
15 Correct 9 ms 1104 KB Output is correct
16 Correct 16 ms 2640 KB Output is correct
17 Correct 12 ms 1104 KB Output is correct
18 Correct 16 ms 1104 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 504 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct