Submission #221871

#TimeUsernameProblemLanguageResultExecution timeMemory
221871davooddkareshkiJJOOII 2 (JOI20_ho_t2)C++17
100 / 100
23 ms9540 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define int long long const int maxn = 5e5+10; const int inf = 2e9+10; string s; int n, k; vector<int> ve[26]; int lst[maxn]; int lj[maxn], lo[maxn], li[maxn]; signed main() { cin>> n >> k >> s; s = "*" + s; // cout<< s <<" "; // cout<< s[n] <<" "; ll ans = inf; for(int i = 1; i <= n; i++) { int x = s[i]-'A'; // cout<< x <<" "; ve[x].push_back(i); // cout<< x <<" "; if(ve[x].size() >= k) { // cout<< ve[x].size() - k <<" "; lst[i] = ve[x][ve[x].size()-k]; } if(s[i] == 'J') lj[i] = i; else lj[i] = lj[i-1]; if(s[i] == 'O') lo[i] = i; else lo[i] = lo[i-1]; if(s[i] == 'I') li[i] = i; else li[i] = li[i-1]; if(s[i] == 'I') { int x = lst[i]; //cout<< x <<" "; x = lo[x]; //cout<< x <<" "; x = lst[x]; //cout<< x <<" "; x = lj[x]; // cout<< x <<" "; x = lst[x]; // cout<< x <<" "; // cout<< if(x > 0) ans = min(ans, i-x+1); } } if(ans == inf) return cout<< -1, 0; cout<< ans - 3 * k; }

Compilation message (stderr)

ho_t2.cpp: In function 'int main()':
ho_t2.cpp:33:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(ve[x].size() >= k)
            ~~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...