Submission #387544

#TimeUsernameProblemLanguageResultExecution timeMemory
387544kimbj0709 Martian DNA (BOI18_dna)C++14
100 / 100
116 ms8192 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int32_t main(){ int no_of_input,base_length,no_of_case; int input1,input2; vector<int> vect1; cin >> no_of_input >> base_length >> no_of_case; vector<int> minimum(base_length,0); vector<int> countt(base_length,0); for(int i=0;i<no_of_input;i++){ cin >> input1; vect1.push_back(input1); } for(int i=0;i<no_of_case;i++){ cin >> input1 >> input2; minimum[input1] = input2; } int currhas=base_length-no_of_case; int pos1 = 0,pos2=0; int ans = INT_MAX; vector<int> temp(base_length,0); for(int i=0;i<no_of_input;i++){ temp[vect1[i]]++; } for(int i=0;i<base_length;i++){ if(temp[i]<minimum[i]){ cout << "impossible"; return 0; } } while(pos1<vect1.size()){ while(pos1<vect1.size()&&currhas<base_length){ if(countt[vect1[pos1]]==minimum[vect1[pos1]]-1){ currhas++; } countt[vect1[pos1]]++; pos1++; } while(pos2<vect1.size()&&pos2<=pos1){ if(countt[vect1[pos2]]==minimum[vect1[pos2]]){ break; } if(pos1==pos2){ break; } countt[vect1[pos2]]--; pos2++; } /*for(int i=0;i<countt.size();i++){ cout << countt[i] << " "; } cout << endl; cout << pos1 << " " << pos2 << endl;*/ ans = min(ans,pos1-pos2); if(pos1<vect1.size()){ countt[vect1[pos1]]++; pos1++; } } //cout << "-------------" << endl; cout << ans; }

Compilation message (stderr)

dna.cpp: In function 'int32_t main()':
dna.cpp:34:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     while(pos1<vect1.size()){
      |           ~~~~^~~~~~~~~~~~~
dna.cpp:35:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         while(pos1<vect1.size()&&currhas<base_length){
      |               ~~~~^~~~~~~~~~~~~
dna.cpp:42:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         while(pos2<vect1.size()&&pos2<=pos1){
      |               ~~~~^~~~~~~~~~~~~
dna.cpp:58:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         if(pos1<vect1.size()){
      |            ~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...