Submission #364121

#TimeUsernameProblemLanguageResultExecution timeMemory
364121Andyvanh1 Martian DNA (BOI18_dna)C++14
100 / 100
40 ms4972 KiB
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(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...