Submission #567914

#TimeUsernameProblemLanguageResultExecution timeMemory
567914BaytoroJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
13 ms3308 KiB
#include <bits/stdc++.h> using namespace std; #define Baytoro_Mayrambekov void solve() #define ios ios::sync_with_stdio(false); cin.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second #define int long long #define endl '\n' const int INF=1e18; void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } int binpow(int a,int n){ if(n==0) return 1; if(n%2==1) return binpow(a, n-1)*a; else{ int b=binpow(a, n/2); return b*b; } } int k,n; vector<int> a,b,c; int get(int i, int j){ int l=lower_bound(all(a),i)-a.begin(); int u=lower_bound(all(c),j)-c.begin(); if(l<k || c.size()-u<k) return INF; int tmp=a[l-k]; int cmp=c[u+k-1]; return cmp-tmp+1-k*3; } int m,i,j,x,y,z,cnt=0,sum=0,res=0; Baytoro_Mayrambekov{ int J=0,O=0,I=0; string s; cin>>n>>k>>s; for(i=0;i<n;i++){ if(s[i]=='J') a.pb(i+1); else if(s[i]=='O') b.pb(i+1); else c.pb(i+1); } res=INF; for(i=0;i<b.size()-k+1;i++){ res=min(res,get(b[i],b[i+k-1])); } if(res==INF) res=-1; cout<<res<<endl; } main(){ ios; int T=1; //cin>>T; while(T--){ solve(); } }

Compilation message (stderr)

ho_t2.cpp: In function 'long long int get(long long int, long long int)':
ho_t2.cpp:32:22: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   32 |  if(l<k || c.size()-u<k)
      |            ~~~~~~~~~~^~
ho_t2.cpp: In function 'void solve()':
ho_t2.cpp:52:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   52 |  for(i=0;i<b.size()-k+1;i++){
      |          ~^~~~~~~~~~~~~
ho_t2.cpp:40:6: warning: unused variable 'J' [-Wunused-variable]
   40 |  int J=0,O=0,I=0;
      |      ^
ho_t2.cpp:40:10: warning: unused variable 'O' [-Wunused-variable]
   40 |  int J=0,O=0,I=0;
      |          ^
ho_t2.cpp:40:14: warning: unused variable 'I' [-Wunused-variable]
   40 |  int J=0,O=0,I=0;
      |              ^
ho_t2.cpp: At global scope:
ho_t2.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main(){
      | ^~~~
ho_t2.cpp: In function 'void fopn(std::string)':
ho_t2.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:15:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...