제출 #1160197

#제출 시각아이디문제언어결과실행 시간메모리
1160197hainam2k9JJOOII 2 (JOI20_ho_t2)C++20
100 / 100
15 ms2888 KiB
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 2e5+5;
const string NAME = "";
int n,k,sum[MAXN][3],rs=1e9;
char c[MAXN];
int bs(int l, int r, int x, int type){
    int rs=-1;
    while(l<=r){
        int mid=(l+r)>>1;
        if(sum[mid][type]-x>=k) rs=mid, r=mid-1;
        else l=mid+1;
    }
    return rs;
}
int main()
{
    tt;
    if(fopen((NAME + ".INP").c_str(), "r")) fo;
    cin >> n >> k;
    for(int i = 1; i<=n; ++i){
        cin >> c[i];
        for(int j = 0; j<3; ++j)
            sum[i][j]=sum[i-1][j];
        if(c[i]=='J') ++sum[i][0];
        else if(c[i]=='O') ++sum[i][1];
        else ++sum[i][2];
    }
    for(int i = 1; i<=n; ++i){
        if(c[i]!='J') continue;
        int pos1=bs(i,n,sum[i-1][0],0), pos2=bs(pos1+1,n,sum[pos1][1],1), pos3=bs(pos2+1,n,sum[pos2][2],2);
        if(pos1!=-1&&pos2!=-1&&pos3!=-1) rs=min(rs,pos3-i+1-k*3);
    }
    if(rs==1e9) rs=-1;
    cout << rs;
}

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

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:36:45: note: in expansion of macro 'fo'
   36 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
ho_t2.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:36:45: note: in expansion of macro 'fo'
   36 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...