Submission #1114935

#TimeUsernameProblemLanguageResultExecution timeMemory
1114935AdamGSJJOOII 2 (JOI20_ho_t2)C++17
13 / 100
9 ms2648 KiB
#include <bits/stdc++.h> using namespace std; constexpr int MAXN = 20007; int J[MAXN]; int O[MAXN]; int I[MAXN]; int main() { int n, k; cin >> n >> k; string s; cin >> s; vector<int> vJ; vector<int> vO; vector<int> vI; for(int i = 0; i < n; ++i) { if(s[i] == 'J') vJ.push_back(i); if(s[i] == 'O') vO.push_back(i); if(s[i] == 'I') vI.push_back(i); } for(int i = 0; i < (int)vJ.size() - k + 1; ++i) J[vJ[i]] = vJ[i+k-1]; for(int i = 0; i < (int)vO.size() - k + 1; ++i) O[vO[i]] = vO[i+k-1]; for(int i = 0; i < (int)vI.size() - k + 1; ++i) I[vI[i]] = vI[i+k-1]; int naso[n]; int nasi[n]; int oo = n; int ii = n; for(int i = n-1; i >= 0; --i) { naso[i] = oo; nasi[i] = ii; if(s[i] == 'O') oo = i; if(s[i] == 'I') ii = i; } int odp = MAXN; for(int i = 0; i < n; ++i) { if(s[i] != 'J') continue; int a = J[i]; if(k != 1 && a == 0) continue; int b = naso[a]; if(b == n) continue; int c = O[b]; if(c == 0) continue; int d = nasi[c]; if(d == n) continue; int e = I[d]; if(e == 0) continue; odp = min(odp, e-i+1); } if(odp == MAXN) { cout << "-1"; return 0; } cout << odp - k*3; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...