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
using namespace std; 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); } int i = 0, j = 0; int question_marks = 0; int sum = 0; vector
cnt(26, 0); while(j < n) { if(*ms.begin() <= k and *ms.rbegin() <= k) { if(s[j] != '?') { sum++; ms.erase(ms.find(cnt[s[j] - 'a'])); cnt[s[j] - 'a']++; ms.insert(cnt[s[j] - 'a']); } else { question_marks++; } j++; if(sum + question_marks == 26 * k) { cout << i + 1 << endl; return 0; } } else { if(s[i] != '?') { sum--; ms.erase(ms.find(cnt[s[i] - 'a'])); cnt[s[i] - 'a']--; ms.insert(cnt[s[i] - 'a']); } else { question_marks--; } i++; if(sum + question_marks == 26 * k) { cout << i << endl; return 0; } } } cout << -1 << endl; return 0; } // a?cdefghijklmnopqrstuvwxyza?
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)