답안 #364121

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
364121 2021-02-08T09:13:10 Z Andyvanh1 Martian DNA (BOI18_dna) C++14
100 / 100
40 ms 4972 KB
using namespace std;


// 17.4.1.2 Headers

// C


#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

void solve(){
    int n, k, r;
    cin>>n>>k>>r;
    vector<int> arr(n);
    for(int i = 0; i < n; i++){
        cin>>arr[i];
    }
    vector<int> need(n);
    for(int i = 0; i < n; i++){
        need[i] = 0;
    }
    for(int i = 0; i < r; i++){
        int a, b;
        cin>>a>>b;
        need[a] = b;
    }

    vector<int> has(n);
    for(int i = 0; i < n; i++){
        has[i] = 0;
    }

    int first = 0;
    int last = -1;
    int flex = r;
    int ans = 1000000;
    while(first!=n||last!=n-1){
        if(last==n-1&&flex!=0){
            break;
        }
        if(flex==0){
            ans = min(ans,last-first+1);
            has[arr[first]]--;
            if(has[arr[first]]<need[arr[first]]){
                flex++;
            }
            first++;
        }else{
            last++;
            has[arr[last]]++;
            if(has[arr[last]]==need[arr[last]]){
                flex--;
            }
        }

    }

    if(ans==1000000){
        cout<<"impossible";
    }else{
        cout<<ans;
    }


}



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





    int tc = 1;
//read(tc);

    while(tc--) {
        //write("Case #", i+1, ": ");
        solve();

    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 3052 KB Output is correct
2 Correct 17 ms 3052 KB Output is correct
3 Correct 18 ms 3180 KB Output is correct
4 Correct 16 ms 3052 KB Output is correct
5 Correct 26 ms 3820 KB Output is correct
6 Correct 16 ms 3052 KB Output is correct
7 Correct 20 ms 3308 KB Output is correct
8 Correct 27 ms 4076 KB Output is correct
9 Correct 20 ms 3840 KB Output is correct
10 Correct 16 ms 3052 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 4588 KB Output is correct
2 Correct 30 ms 4332 KB Output is correct
3 Correct 25 ms 3948 KB Output is correct
4 Correct 16 ms 3052 KB Output is correct
5 Correct 36 ms 4972 KB Output is correct
6 Correct 40 ms 4716 KB Output is correct
7 Correct 20 ms 3692 KB Output is correct
8 Correct 24 ms 3820 KB Output is correct
9 Correct 16 ms 3052 KB Output is correct
10 Correct 19 ms 3052 KB Output is correct
11 Correct 19 ms 3180 KB Output is correct
12 Correct 16 ms 3052 KB Output is correct
13 Correct 35 ms 3820 KB Output is correct
14 Correct 18 ms 3052 KB Output is correct
15 Correct 17 ms 3308 KB Output is correct
16 Correct 24 ms 3948 KB Output is correct
17 Correct 19 ms 3692 KB Output is correct
18 Correct 18 ms 3052 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct