Submission #203552

#TimeUsernameProblemLanguageResultExecution timeMemory
203552arman_ferdousJJOOII 2 (JOI20_ho_t2)C++14
100 / 100
13 ms2936 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5+100; int n, k; char s[N]; int J[N], O[N], I[N]; int main() { scanf("%d %d %s", &n, &k, s + 1); int ptr = -1, cnt = 0; for(int i = 1; i <= n; i++) { while(ptr + 1 <= n && cnt < k) { ptr++; if(s[ptr] == 'J') cnt++; } if(cnt == k) J[i] = ptr; if(s[i] == 'J') cnt--; } ptr = -1, cnt = 0; for(int i = 1; i <= n; i++) { while(ptr + 1 <= n && cnt < k) { ptr++; if(s[ptr] == 'O') cnt++; } if(cnt == k) O[i] = ptr; if(s[i] == 'O') cnt--; } ptr = -1, cnt = 0; for(int i = 1; i <= n; i++) { while(ptr + 1 <= n && cnt < k) { ptr++; if(s[ptr] == 'I') cnt++; } if(cnt == k) I[i] = ptr; if(s[i] == 'I') cnt--; } int ans = n * 3; for(int i = 1; i <= n; i++) { int to = I[O[J[i]]]; if(to >= i) ans = min(ans, to - i + 1 - 3 * k); } if(ans == n * 3) ans = -1; printf("%d\n", ans); return 0; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %s", &n, &k, s + 1);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...