Submission #1012470

#TimeUsernameProblemLanguageResultExecution timeMemory
1012470AlmontherDifference (POI11_roz)C++98
100 / 100
526 ms26596 KiB
#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[27]; ll pref[1000001],arr[1000001]; void solve(){ cin>>n>>s; for(int i=0;i<n;i++) v[s[i]-'a'].push_back(i); for(int i=0;i<26;i++){ if(v[i].size()==0) continue; for(int j=0;j<26;j++){ if(v[j].size()==0) continue; ll l,r; l=r=0; while(l!=v[i].size()||r!=v[j].size()){ if(l==v[i].size()){ r++; arr[l+r]=-1; } else if(r==v[j].size()){ l++; arr[l+r]=1; } else if(v[i][l]<v[j][r]){ l++; arr[l+r]=1; } else{ r++; arr[l+r]=-1; } } ll mn=1e18; pref[0]=0; for(int k=1;k<=l+r;k++) pref[k]=pref[k-1]+arr[k]; ll last=0; for(int k=1;k<=l+r;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 (stderr)

roz.cpp: In function 'void solve()':
roz.cpp:22: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]
   22 |             while(l!=v[i].size()||r!=v[j].size()){
      |                   ~^~~~~~~~~~~~~
roz.cpp:22: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]
   22 |             while(l!=v[i].size()||r!=v[j].size()){
      |                                   ~^~~~~~~~~~~~~
roz.cpp:23: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]
   23 |                 if(l==v[i].size()){
      |                    ~^~~~~~~~~~~~~
roz.cpp:27: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]
   27 |                 else if(r==v[j].size()){
      |                         ~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...