Submission #391012

#TimeUsernameProblemLanguageResultExecution timeMemory
391012lukameladzeJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
16 ms14784 KiB
# include <bits/stdc++.h> #define f first #define s second #define pb push_back using namespace std; const int N=5e5+5; long long n,k,cntj,cnto,cnti,prj[N],pri[N],pro[N],ans,ans1,nxt,xx,le,ri,le1,ri1,le2,ri2; string s; long long mpj[N],mpi[N],mpo[N],idx,pr; int main() { cin>>n>>k; cin>>s; for (int i=0; i<=2*n; i++) { mpj[i]=-1; mpo[i]=-1; mpi[i]=-1; } for (int i=0; i<s.size(); i++) { if (s[i]=='J') cntj++, mpj[cntj]=i; if (s[i]=='O') cnto++, mpo[cnto]=i; if (s[i]=='I') cnti++, mpi[cnti]=i; prj[i]=cntj; pro[i]=cnto; pri[i]=cnti; } ans=1e9; for (int le=k; le<=n-k-1; le++) { idx=le; xx=pro[le-1]; nxt=k+pro[le-1]; ri=mpo[nxt]; if (-1==mpo[nxt]) continue; ans1=(ri-le+1)-k; ri1=le-1; xx=prj[ri1]; pr=xx-k+1; if (pr<=0) continue; le1=mpj[pr]; if (-1==mpj[pr]) continue; ans1+=(ri1-le1+1)-k; le2=ri+1; nxt=pri[ri]+k; ri2=mpi[nxt]; if (-1==mpi[nxt]) continue; ans1+=(ri2-le2+1)-k; ans=min(ans,ans1); }if (ans==1e9) cout<<-1<<endl; else cout<<ans<<endl; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:18:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |      for (int i=0; i<s.size(); i++) {
      |                    ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...