Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
#include
#include
#include
using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); int n, k; cin >> n >> k; string s; cin >> s; multiset
ms; for(int i = 0; i < 26; i++) { ms.insert(0); } vector
cnt(26, 0); int i = 0, j = 0; int question_marks = 0; int chars = 0; while(j < n) { if(*ms.begin() <= k and *ms.rbegin() <= k) { if(s[j] == '?') { question_marks++; } else { chars++; ms.erase(ms.find(cnt[s[j] - 'a'])); cnt[s[j] - 'a']++; ms.insert(cnt[s[j] - 'a']); } j++; if(chars + question_marks == 26 * k) { cout << i + 1 << endl; return 0; } } else { if(s[i] == '?') { question_marks--; } else { chars--; ms.erase(ms.find(cnt[s[i] - 'a'])); cnt[s[i] - 'a']--; ms.insert(cnt[s[i] - 'a']); } i++; if(chars + question_marks == 26 * k) { cout << i << endl; return 0; } } } cout << -1 << endl; return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)