| Task: | Matter++ |
| Sender: | aalto26im_018 |
| Submission time: | 2026-11-02 17:38:29 +0200 |
| Language: | C++ (C++20) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:12:18: error: expected ';' before 'int'
12 | cin >> W >> s
| ^
| ;
13 |
14 | int n = s.length();
| ~~~
input/code.cpp:19:19: error: 'n' was not declared in this scope
19 | int min_len = n + 1;
| ^Code
#include <iostream>
#include <string>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long W;
string s;
cin >> W >> s
int n = s.length();
long long cnt[26] = {0};
long long pot = 0;
int best_l = 0;
int min_len = n + 1;
int l = 0;
for (int r = 0; r < n; ++r) {
int c_in = s[r] - 'a';
pot += 2 * cnt[c_in] + 1;
cnt[c_in]++;
while (pot >= W) {
if (r - l + 1 < min_len) {
min_len = r - l + 1;
best_l = l;
}
int c_out = s[l] - 'a';
cnt[c_out]--;
pot -= 2 * cnt[c_out] + 1;
l++;
}
}
cout << s.substr(best_l, min_len) << "\n";
return 0;
}