답안 #391003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391003 2021-04-17T14:47:10 Z lukameladze JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
1 ms 332 KB
# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N=3e5+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<=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; 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;
      //    cout<<pr<<endl;
          le1=mpj[pr];
          //cout<<le1<<" "<<ri1<<endl;
          if (-1==mpj[pr]) continue;
          ans1+=(ri1-le1+1)-k;
          le2=ri+1;
          nxt=pri[ri]+k;
          ri2=mpi[nxt];
         // cout<<ri2<<endl;
         //cout<<le2<<" "<<ri2<<endl;
          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

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++) {
      |                    ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -