답안 #547973

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
547973 2022-04-12T05:23:09 Z Jarif_Rahman Martian DNA (BOI18_dna) C++17
100 / 100
147 ms 137676 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, k, r; cin >> n >> k >> r;

    vector<int> v(n);
    for(int &x: v) cin >> x;

    vector<queue<int>> sth(k);
    vector<int> req(k, 0);

    for(int i = 0; i < r; i++){
        int b, q; cin >> b >> q;
        req[b] = q;
    }
    
    int tbo = r;
    set<int> ss;
    int ans = 1e9;

    for(int i = 0; i < n; i++){
        if(sth[v[i]].size() < req[v[i]]){
            sth[v[i]].push(i);
            ss.insert(i);
            if(sth[v[i]].size() == req[v[i]]) tbo--;
        }
        else if(req[v[i]] != 0){
            sth[v[i]].push(i);
            ss.insert(i);
            ss.erase(sth[v[i]].front());
            sth[v[i]].pop();
        }

        if(tbo == 0) ans = min(ans, i-*ss.begin()+1);
    }

    if(ans > n) cout << "impossible\n";
    else cout << ans << "\n";
}

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:31:29: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   31 |         if(sth[v[i]].size() < req[v[i]]){
dna.cpp:34:33: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
   34 |             if(sth[v[i]].size() == req[v[i]]) tbo--;
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 2004 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 1 ms 1356 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 316 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 6028 KB Output is correct
2 Correct 37 ms 3432 KB Output is correct
3 Correct 33 ms 1492 KB Output is correct
4 Correct 41 ms 4520 KB Output is correct
5 Correct 48 ms 56392 KB Output is correct
6 Correct 44 ms 11724 KB Output is correct
7 Correct 18 ms 1876 KB Output is correct
8 Correct 117 ms 137668 KB Output is correct
9 Correct 18 ms 7380 KB Output is correct
10 Correct 55 ms 5336 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 2 ms 1996 KB Output is correct
14 Correct 3 ms 2976 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 324 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 60796 KB Output is correct
2 Correct 102 ms 46148 KB Output is correct
3 Correct 72 ms 43852 KB Output is correct
4 Correct 21 ms 1488 KB Output is correct
5 Correct 127 ms 78528 KB Output is correct
6 Correct 147 ms 130028 KB Output is correct
7 Correct 86 ms 11328 KB Output is correct
8 Correct 109 ms 17868 KB Output is correct
9 Correct 44 ms 6064 KB Output is correct
10 Correct 39 ms 3540 KB Output is correct
11 Correct 30 ms 1492 KB Output is correct
12 Correct 43 ms 4584 KB Output is correct
13 Correct 49 ms 56428 KB Output is correct
14 Correct 44 ms 11648 KB Output is correct
15 Correct 17 ms 1864 KB Output is correct
16 Correct 96 ms 137676 KB Output is correct
17 Correct 20 ms 7440 KB Output is correct
18 Correct 60 ms 5456 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 468 KB Output is correct
21 Correct 2 ms 2004 KB Output is correct
22 Correct 2 ms 3028 KB Output is correct
23 Correct 1 ms 1360 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 320 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 212 KB Output is correct