제출 #747683

#제출 시각아이디문제언어결과실행 시간메모리
747683Sami_MassahJJOOII 2 (JOI20_ho_t2)C++17
13 / 100
6 ms1300 KiB
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e3 + 12, mod = 1e9 + 7, inf = 1e9 + 12 ; long long n, k, cnt[maxn]; vector<int> locs[3]; string s; int main(){ cin >> n >> k; cin >> s; cnt[1] = (s[0] == 'O'); for(int i = 1; i < n; i++) if(s[i] == 'O') cnt[i] = cnt[i - 1] + 1; else cnt[i] = cnt[i - 1]; for(int i = 0; i < n; i++) if(s[i] == 'J') locs[0].push_back(i); else if(s[i] == 'O') locs[1].push_back(i); else locs[2].push_back(i); long long ans = maxn; for(int loc = 0; loc + k - 1 < locs[0].size(); loc++){ int ne = locs[0][loc + k - 1]; int l = -1, r = locs[2].size() - k + 1, mid; while(r - l != 1){ int mid = (l + r) / 2; if(cnt[locs[2][mid]] - cnt[ne] >= k) r = mid; else l = mid; } if(r != locs[2].size() - k + 1) ans = min(ans, locs[2][r + k - 1] - locs[0][loc] + 1 - k * 3); } if(ans == maxn) ans = -1; cout << ans << endl; }

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

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:26:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int loc = 0; loc + k - 1 < locs[0].size(); loc++){
      |                      ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:38:14: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   38 |         if(r != locs[2].size() - k + 1)
      |            ~~^~~~~~~~~~~~~~~~~~~~~~~~~
ho_t2.cpp:28:49: warning: unused variable 'mid' [-Wunused-variable]
   28 |         int l = -1, r = locs[2].size() - k + 1, mid;
      |                                                 ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...