| Task: | Matter++ |
| Sender: | aalto26im_017 |
| Submission time: | 2026-11-02 16:51:35 +0200 |
| Language: | C++ (C++20) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:19:16: error: 'll_MAX' was not declared in this scope
19 | ll bestVal=ll_MAX;
| ^~~~~~
input/code.cpp:21:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | while (r<s.size()){
| ~^~~~~~~~~Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
int main(){
ll w;
string s;
cin >> w >> s;
unordered_map<char, ll> m;
ll l=0, r=0;
ll curr=1;
m[s[0]]++;
ll bestVal=ll_MAX;
pair<ll,ll> bestIndex;
while (r<s.size()){
if (curr<w){
r++;
ll oldVal=m[s[r]];
curr=curr-pow(oldVal,2)+pow(oldVal+1,2);
m[s[r]]++;
} else {
ll oldVal=m[s[l]];
curr=curr-pow(oldVal,2)+pow(oldVal-1,2);
m[s[l]]--;
l++;
}
if (curr>=w){
if (curr<bestVal){
bestVal=curr;
bestIndex.F=l;
bestIndex.S=r;
}
}
}
for (ll i=bestIndex.F; i<=bestIndex.S; i++){
cout << s[i];
}
cout << '\n';
return 0;
}