Submission #867640

#TimeUsernameProblemLanguageResultExecution timeMemory
867640MongHwaJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
7 ms3048 KiB
#include <iostream> #include <queue> #include <deque> using namespace std; #define INF 0x7f7f7f7f int jpos[200001], ipos[200001]; queue<int> qj, qi; deque<int> dq; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; string s; cin >> n >> k >> s; fill(jpos, jpos+n, -1); fill(ipos, ipos+n, -1); for(int i = 0; i < n; i++) { if(s[i] == 'J') { qj.push(i); if(qj.size() > k) qj.pop(); } else if(s[i] == 'O') if(qj.size() == k) jpos[i] = qj.front(); } for(int i = n-1; i >= 0; i--) { if(s[i] == 'I') { qi.push(i); if(qi.size() > k) qi.pop(); } else if(s[i] == 'O') if(qi.size() == k) ipos[i] = qi.front(); } int ans = INF; for(int i = 0; i < n; i++) if(s[i] == 'O') { dq.push_back(i); if(dq.size() == k) { if(ipos[dq.back()] != -1 && jpos[dq.front()] != -1) ans = min(ans, ipos[dq.back()]-jpos[dq.front()]+1); dq.pop_front(); } } cout << (ans == INF ? -1 : ans-k*3) << '\n'; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:28:17: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |    if(qj.size() > k)
      |       ~~~~~~~~~~^~~
ho_t2.cpp:32:17: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |    if(qj.size() == k)
      |       ~~~~~~~~~~^~~~
ho_t2.cpp:41:17: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |    if(qi.size() > k)
      |       ~~~~~~~~~~^~~
ho_t2.cpp:45:17: warning: comparison of integer expressions of different signedness: 'std::queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |    if(qi.size() == k)
      |       ~~~~~~~~~~^~~~
ho_t2.cpp:54:17: warning: comparison of integer expressions of different signedness: 'std::deque<int, std::allocator<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |    if(dq.size() == k)
      |       ~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...