Submission #1088770

# Submission time Handle Problem Language Result Execution time Memory
1088770 2024-09-15T02:57:47 Z ntdaccode JJOOII 2 (JOI20_ho_t2) C++17
0 / 100
1 ms 2392 KB
#include<bits/stdc++.h>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod=1e9+7;
const int M=2e5+10;
const int N=1e3+10;
int n,k;
string s;
int sum[3][M];
char ch[3]={'J','O','I'};
bool check(int l,int r)
{
  fori(i,0,2) if(sum[i][r]-sum[i][l-1]<k) return false;
  return true;
}
int id(char ch2)
{
  fori(i,0,2) if(ch2==ch[i]) return i;
}
vector<int> v[4];
int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  #define task "1"
  if(fopen(task".inp","r"))
  {
    freopen(task".inp","r",stdin);
    freopen(task".out","w",stdout);
  }
  cin >> n >> k;
  cin >> s;
  s=' '+s;
  fori(i,1,n) v[id(s[i])].pb(i);
  fori(i,1,n+1)
  {
    sum[0][i]=-1e9;
    sum[2][i]=1e9;
  }
  int kq=1e9;
  for(int i=k-1;i<=v[0].size()-1;i++) sum[0][v[0][i]]=v[0][i-k+1];
  fori(i,1,n) sum[0][i]=max(sum[0][i-1],sum[0][i]);
  for(int i=v[2].size()-k;i>=0;i--) sum[2][v[2][i]]=v[2][i+k-1];
  for(int i=n;i!=0;i--) sum[2][i]=min(sum[2][i],sum[2][i+1]);
  //fori(i,1,n) cout << sum[0][i] << " " << sum[2][i] << "\n";
  for(int i=k-1;i<=v[1].size()-1;i++) kq=min(kq,sum[2][v[1][i]]-sum[0][v[1][i-k+1]]+1);
  cout << (kq>n ? -1 :kq-3*k);
}



Compilation message

ho_t2.cpp: In function 'int32_t main()':
ho_t2.cpp:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(int i=k-1;i<=v[0].size()-1;i++) sum[0][v[0][i]]=v[0][i-k+1];
      |                 ~^~~~~~~~~~~~~~~
ho_t2.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for(int i=k-1;i<=v[1].size()-1;i++) kq=min(kq,sum[2][v[1][i]]-sum[0][v[1][i-k+1]]+1);
      |                 ~^~~~~~~~~~~~~~~
ho_t2.cpp: In function 'int id(char)':
ho_t2.cpp:24:1: warning: control reaches end of non-void function [-Wreturn-type]
   24 | }
      | ^
ho_t2.cpp: In function 'int32_t main()':
ho_t2.cpp:34:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     freopen(task".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:35:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     freopen(task".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 0 ms 344 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 0 ms 344 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 0 ms 344 KB Output isn't correct
10 Halted 0 ms 0 KB -