제출 #515961

#제출 시각아이디문제언어결과실행 시간메모리
515961David_MJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
7 ms5972 KiB
#include <bits/stdc++.h> #define ll long long #define F first #define S second #define all(x) (x).begin(), (x).end() #define pii pair<int, int> #define FF first.first #define FS first.second #define pb push_back using namespace std; const ll N=1000006, INF=1e18, P=998244353; ll q=1, n, m, x, y, z, l, r, c, k, a[N], b[3][N], f[N], ansl, ansr, ans, o, u, Ans[N]; vector <ll> v[3]; string s; void solve(){ cin>>n>>k>>s; for (int i=0; i<n; i++){ a[i]=(s[i]=='J')?0:((s[i]=='O')?1:2); v[a[i]].pb(i); } for (int i=0; i<k; i++)v[1].pb(INF),v[2].pb(2*INF); ans=INF; for (int x0=0, x1=0, x2=0; x0+k-1<v[0].size(); x0++){ while(v[1][x1]<v[0][x0+k-1])x1++; while(v[2][x2]<v[1][x1+k-1])x2++; ans=min(ans, v[2][x2+k-1]-v[0][x0]+1-3*k); } cout<<(ans>n?-1:ans); } main(){ios_base::sync_with_stdio(false), cin.tie(0); int T=1; //cin>>T; while(T--){ solve(); } }

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

ho_t2.cpp: In function 'void solve()':
ho_t2.cpp:25:38: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int x0=0, x1=0, x2=0; x0+k-1<v[0].size(); x0++){
      |                                ~~~~~~^~~~~~~~~~~~
ho_t2.cpp: At global scope:
ho_t2.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 | main(){ios_base::sync_with_stdio(false), cin.tie(0);
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...