Submission #656843

#TimeUsernameProblemLanguageResultExecution timeMemory
656843jcelin Martian DNA (BOI18_dna)C++14
100 / 100
109 ms19848 KiB
#include <bits/stdc++.h> //#include<ext/pb_ds/assoc_container.hpp> //#include<ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef unsigned int ui; #define ii pair<int,int> #define pll pair<ll,ll> #define vi vector<int> #define vii vector<ii> #define vll vector<ll> #define vpll vector<pll> #define matrix vector<vi> #define matrixLL vector<vll> #define vs vector<string> #define vui vector<ui> #define msi multiset<int> #define mss multiset<string> #define si set<int> #define ss set<string> #define PB push_back #define PF push_front #define PPB pop_back #define PPF pop_front #define X first #define Y second #define MP make_pair #define FOR(i, a, b) for (int i = int(a); i < int(b); i++) #define REP(i, n) FOR(i, 0, n) #define all(x) (x).begin(), (x).end() const int dx[] = {-1, 1, 0, 0}; const int dy[] = {0, 0, -1, 1}; const int dxx[] = {-1, 1, 0, 0, 1, 1, -1, -1}; const int dyy[] = {0, 0, -1, 1, -1, 1, -1, 1}; const string abc="abcdefghijklmnopqrstuvwxyz"; const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const ld pi = 3.14159265; const int mod = 1e9 + 7; const int MOD = 1e9 + 7; const int MAXN = 2e5 + 7; const int inf = mod; const ll INF = 1e18; const ll zero = ll(0); const int logo = 20; const int off = 1 << logo; const int trsz = off << 1; vi ind[MAXN]; int req[MAXN]; int arr[MAXN]; set<int> cur; //prvi int point[MAXN]; void solve(){ int n, r, k; cin >> n >> k >> r; for(int i=0; i<n; i++){ int x; cin >> x; arr[i] = x; ind[x].PB(i); } for(int i=0; i<r; i++){ int a, b; cin >> a >> b; req[a] = b; } for(int i=0; i<k; i++){ if(req[i] > ind[i].size()){ cout << "impossible\n"; return; } for(int j=0; j<req[i]; j++) cur.insert(ind[i][j]); point[i] = req[i] - 1; } int ans = 0; if(cur.size()) ans = *(--cur.end()) - *cur.begin(); for(int i=1; i<n; i++){ int pre = arr[i - 1]; if(req[pre] == 0) continue; cur.erase(i - 1); if(point[pre] >= ind[pre].size() - 1) break; point[pre]++; cur.insert(ind[pre][point[pre]]); if(cur.size()) ans = min(ans, *(--cur.end()) - *cur.begin()); } cout << ans + 1 << "\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t=1; //cin >> t; while(t--)solve(); return 0; }

Compilation message (stderr)

dna.cpp: In function 'void solve()':
dna.cpp:81:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |   if(req[i] > ind[i].size()){
      |      ~~~~~~~^~~~~~~~~~~~~~~
dna.cpp:99:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |   if(point[pre] >= ind[pre].size() - 1) break;
      |      ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...