Submission #1012465

# Submission time Handle Problem Language Result Execution time Memory
1012465 2024-07-02T08:13:31 Z Almonther Difference (POI11_roz) C++
60 / 100
1000 ms 15888 KB
#include<bits/stdc++.h>

#define ll long long
#define co cout<<
#define suiii ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
// stuff
ll n;
string s;
ll mx=0;
vector<ll>v[100];
void solve(){
    cin>>n>>s;
    for(int i=0;i<n;i++) v[s[i]-'a'].push_back(i);
    for(int i=0;i<27;i++){
        if(v[i].size()==0) continue;
        for(int j=0;j<27;j++){
            if(v[j].size()==0) continue;
            ll l,r;
            l=r=0;
            vector<ll>arr;
            vector<ll>pref;
            while(l!=v[i].size()||r!=v[j].size()){
                if(l==v[i].size()){
                    r++;
                    arr.push_back(-1);
                }
                else if(r==v[j].size()){
                    l++;
                    arr.push_back(1);
                }
                else if(v[i][l]<v[j][r]){
                    l++;
                    arr.push_back(1);
                }
                else{
                    r++;
                    arr.push_back(-1);
                }
            }
            ll curr=0;
            ll mn=1e18;
            for(auto k:arr){
                curr+=k;
                pref.push_back(curr);
            }
            ll last=0;
            for(int k=0;k<pref.size();k++){
                if(arr[k]==-1){
                    for(int r=last;r<k;r++) mn=min(mn,pref[r]);
                    mn=min(mn,0ll);
                    last=k;
                }
                mx=max(mx,pref[k]-mn);
            }
        }
    }
    co mx;
}

int main(){
    suiii
    int tt=1;
    // cin>>tt;
    while(tt--){
        solve();
    }
}

Compilation message

roz.cpp: In function 'void solve()':
roz.cpp:23:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |             while(l!=v[i].size()||r!=v[j].size()){
      |                   ~^~~~~~~~~~~~~
roz.cpp:23:36: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |             while(l!=v[i].size()||r!=v[j].size()){
      |                                   ~^~~~~~~~~~~~~
roz.cpp:24:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |                 if(l==v[i].size()){
      |                    ~^~~~~~~~~~~~~
roz.cpp:28:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |                 else if(r==v[j].size()){
      |                         ~^~~~~~~~~~~~~
roz.cpp:48:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |             for(int k=0;k<pref.size();k++){
      |                         ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 1756 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 6 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1050 ms 15832 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1038 ms 15728 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1057 ms 15888 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1048 ms 15688 KB Time limit exceeded
2 Halted 0 ms 0 KB -