Submission #245150

# Submission time Handle Problem Language Result Execution time Memory
245150 2020-07-05T15:52:37 Z uacoder123 JJOOII 2 (JOI20_ho_t2) C++14
0 / 100
5 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
 
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lli test=1;
  for(;test>0;--test)
  {
    int n,l,r,k,c=0,ans=0;
    string s;
    cin>>n>>k>>s;
    l=0;
    r=s.size()-1;
    while(l<s.size()&&s[l]!='J')
      l++;
    while(l<s.size()&&c!=k)
    {
      if(s[l]!='J')
        ans++;
      else
        c++;
      l++;
    }
    if(c!=k)
    {
      cout<<"-1"<<endl;
      exit(0);
    }
    c=0;
    while(r>l&&s[r]!='I')
      r--;
    while(r>l&&c!=k)
    {
      if(s[r]!='I')
        ans++;
      else
        c++;
      r--;
    }
    if(c!=k)
    {
      cout<<"-1"<<endl;
      exit(0);
    }
    c=0;
    while(l<=r&&c!=k)
    {
      if(s[l]!='O')
        ans++;
      else
        c++;
      l++;
    }
    if(c!=k)
    {
      cout<<"-1"<<endl;
      exit(0);
    }
    cout<<ans<<endl;
  }
  return(0);
}

Compilation message

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:30:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(l<s.size()&&s[l]!='J')
           ~^~~~~~~~~
ho_t2.cpp:32:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(l<s.size()&&c!=k)
           ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 4 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 4 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 4 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -