Submission #1114928

#TimeUsernameProblemLanguageResultExecution timeMemory
1114928AdamGSJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
1192 ms2184 KiB
#include<iostream> #include<vector> #include<algorithm> #include<set> #include<string> using namespace std; int bin(int co, vector<int> v) { int pocz = 0, kon = v.size() - 1, sr; while(pocz < kon) { sr = (pocz + kon) / 2; if (v[sr] < co) { pocz = sr + 1; } else { kon = sr; } } return pocz; } int main() { int n, k; cin >> n >> k; string joi; cin >> joi; vector<vector<int>> od(3, vector<int>()); for (int i = 0; i < n; i++) { if (joi[i] == 'J') { od[0].push_back(i); } else if(joi[i] == 'O') { od[1].push_back(i); } else if(joi[i] == 'I') { od[2].push_back(i); } } int w = -1; for (int i = 0; i < od[0].size(); i++) { int ak = i; if (i + k - 1 <= od[0].size() - 1) { ak = od[0][i + k - 1]; if (upper_bound(od[1].begin(), od[1].end(), ak) != od[1].end()) { ak = *upper_bound(od[1].begin(), od[1].end(), ak); ak = bin(ak, od[1]); if (ak + k - 1 <= od[1].size() - 1) { ak = od[1][ak + k - 1]; if (upper_bound(od[2].begin(), od[2].end(), ak) != od[2].end()) { ak = *upper_bound(od[2].begin(), od[2].end(), ak); ak = bin(ak, od[2]); if (ak + k - 1 <= od[2].size() - 1) { ak = od[2][ak + k - 1]; if (ak - od[0][i] + 1 - 3 * k < w || w == -1) { w = ak - od[0][i] + 1 - 3 * k; } } } } } } } cout << w; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (int i = 0; i < od[0].size(); i++) {
      |                     ~~^~~~~~~~~~~~~~
ho_t2.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         if (i + k - 1 <= od[0].size() - 1) {
      |             ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
ho_t2.cpp:45:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |                 if (ak + k - 1 <= od[1].size() - 1) {
      |                     ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
ho_t2.cpp:50:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |                         if (ak + k - 1 <= od[2].size() - 1) {
      |                             ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...