답안 #696479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696479 2023-02-06T15:26:58 Z josiftepe Martian DNA (BOI18_dna) C++14
16 / 100
2000 ms 340 KB
#include <iostream>
#include <vector>
#include <map>
using namespace std;



int main()
{
    ios_base::sync_with_stdio(false);
    int n, k;
    cin>>n >> k;
    int m;
    cin>>m;
    if(n > 5000) {
        return 0;
    }
    vector<int> req(k + 1, 0);
    
    vector<int>v;
    
    for(int i=0; i<n; i++){
        int a;
        cin>>a;
        v.push_back(a);
    }
    int zbir=0;
    for(int j=0; j<m; j++){
    int a, b;
    cin>>a>>b;
        req[a] = b;
    zbir+=b;
    }

    int min_length=2e9;
    int tmp=0;
    vector<int> t = req;
    
    for(int i=0; i<n; i++){
        req = t;
        for(int j=i; j<n; j++){
            req[v[j]]--;
            bool ok = true;
            for(int x = 0; x < req.size(); x++) {
                if(req[x] > 0) {
                    ok = false;
                    break;
                }
            }
            if(ok) {
                min_length = min(min_length, j - i);
            }
        }
    }
    if(min_length == 2e9) {
        cout << "impossible";
    }
    else
    cout << min_length + 1 << endl;
    return 0;
}
/*
 5 2 2
 0 1 1 0 1
 0 1
1 1
 
 13 4 3
 1 1 3 2 0 1 2 0 0 0 0 3 1
 0 2
 2 1
 1 2
 
 5 3 1
 1 2 0 1 2
 0 2
 **/

Compilation message

dna.cpp: In function 'int main()':
dna.cpp:44:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |             for(int x = 0; x < req.size(); x++) {
      |                            ~~^~~~~~~~~~~~
dna.cpp:36:9: warning: unused variable 'tmp' [-Wunused-variable]
   36 |     int tmp=0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 340 KB Output is correct
2 Correct 32 ms 340 KB Output is correct
3 Correct 1733 ms 340 KB Output is correct
4 Execution timed out 2073 ms 340 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -