Submission #364835

#TimeUsernameProblemLanguageResultExecution timeMemory
364835cpp219JJOOII 2 (JOI20_ho_t2)C++14
13 / 100
2072 ms2100 KiB
#include <bits/stdc++.h> #define ll int #define ld long double #define fs first #define sc second using namespace std; const ll N = 2e5 + 3; const ll inf = 1e9 + 7; typedef pair<int,int> LL; string s; ll n,k; vector<ll> J,O,I; ll Forwardk(ll pos,vector<ll> v){ ll now = lower_bound(v.begin(),v.end(),pos) - v.begin(); now += k - 1; if (now < v.size()) return v[now]; return -1; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "tst" if (fopen(task".INP","r")){ freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } cin>>n>>k>>s; s = " " + s; for (ll i = 1;i <= n;i++){ if (s[i] == 'J') J.push_back(i); if (s[i] == 'O') O.push_back(i); if (s[i] == 'I') I.push_back(i); } ll ans = inf; for (ll i = 1;i <= n;i++){ if (s[i] != 'J') continue; ll p = Forwardk(i,J); if (p == -1) break; p = Forwardk(p,O); if (p == -1) break; p = Forwardk(p,I); if (p == -1) break; ans = min(ans,p - i + 1 - 3*k); } cout<<(ans == inf ? -1 : ans); }

Compilation message (stderr)

ho_t2.cpp: In function 'int Forwardk(int, std::vector<int>)':
ho_t2.cpp:17:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     if (now < v.size()) return v[now];
      |         ~~~~^~~~~~~~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   26 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...