제출 #667036

#제출 시각아이디문제언어결과실행 시간메모리
667036Darren0724JJOOII 2 (JOI20_ho_t2)C++17
100 / 100
10 ms5976 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(),x.end() int INF=1e18; signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n,k;cin>>n>>k; string s;cin>>s; vector<int> pre(n); pre[0]=(s[0]=='O'); for(int i=1;i<n;i++){ pre[i]=pre[i-1]+(s[i]=='O'); } auto f=[&](int a,int b)->int{ if(a>b){ return 0; } if(a==0){ return pre[b]; } return pre[b]-pre[a-1]; }; vector<int> dp1(n),dp2(n); int cnt=0; queue<int> q; for(int i=0;i<n;i++){ if(s[i]=='J'){ q.push(i); } if(q.size()>k){ q.pop(); } if(q.size()<k){ dp1[i]=-INF; } else{ dp1[i]=q.front(); } } while(q.size()){ q.pop(); } for(int i=n-1;i>=0;i--){ if(s[i]=='I'){ q.push(i); } if(q.size()>k){ q.pop(); } if(q.size()<k){ dp2[i]=INF; } else{ dp2[i]=q.front(); } } int j=n-1; int ans=INF; for(int i=n-2;i>=0;i--){ while(f(i+1,j-2)>=k){ j--; } if(f(i+1,j-1)>=k){ ans=min(ans,dp2[j]-dp1[i]+1-k*3); } } if(ans>=n){ cout<<-1<<endl; } else{ cout<<ans<<endl; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:32:20: warning: comparison of integer expressions of different signedness: 'std::queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   32 |         if(q.size()>k){
      |            ~~~~~~~~^~
ho_t2.cpp:35:20: warning: comparison of integer expressions of different signedness: 'std::queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   35 |         if(q.size()<k){
      |            ~~~~~~~~^~
ho_t2.cpp:49:20: warning: comparison of integer expressions of different signedness: 'std::queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   49 |         if(q.size()>k){
      |            ~~~~~~~~^~
ho_t2.cpp:52:20: warning: comparison of integer expressions of different signedness: 'std::queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   52 |         if(q.size()<k){
      |            ~~~~~~~~^~
ho_t2.cpp:26:9: warning: unused variable 'cnt' [-Wunused-variable]
   26 |     int cnt=0;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...