QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#71565 | #3236. Hills And Valleys | zhangboju# | AC ✓ | 151ms | 11604kb | C++17 | 1.5kb | 2023-01-11 11:52:50 | 2023-01-11 11:52:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &x)
{
x=0;short f=1;char c=getchar();
for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
x*=f;return;
}
const int N=1e5+5;
int n,a[N];
int f[N][10],g[N][10];
char s[N];
pair<int,int>h[10];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;cin>>T;
while(T--)
{
cin>>n;
cin>>s+1;
for(int i=1;i<=n;++i)
a[i]=s[i]-'0';
for(int i=1;i<=n+1;++i)
for(int j=0;j<10;++j)
f[i][j]=g[i][j]=0;
for(int i=1;i<=n;++i)
for(int j=0;j<10;++j)
{
if(j>0) f[i][j]=max(f[i][j],f[i][j-1]);
f[i][j]=max(f[i][j],f[i-1][j]+(a[i]==j));
}
for(int i=n;i;--i)
for(int j=9;j>=0;--j)
{
if(j<9) g[i][j]=max(g[i][j],g[i][j+1]);
g[i][j]=max(g[i][j],g[i+1][j]+(a[i]==j));
}
int ans=0,ansl=1,ansr=1;
for(int x=0;x<=9;++x)
{
for(int y=x;y<=9;++y)
{
for(int i=0;i<10;++i)
h[i]={0,0};
for(int i=1;i<=n;++i)
{
h[y]=max(h[y],make_pair(f[i-1][x],i));
for(int j=y;j>=x;--j)
{
if(j<y)
h[j]=max(h[j],h[j+1]);
if(a[i]==j) h[j].first++;
if(h[j].first+g[i+1][y]>ans)
{
ans=h[j].first+g[i+1][y];
ansl=h[j].second,ansr=i;
}
}
}
}
}
cout<<ans<<" "<<ansl<<" "<<ansr<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 151ms
memory: 11604kb
input:
100 564 3348010339062339968164170543732424036101480063385567796871300633327190066610177797479597931706239956680908434521050648311220502482402268964497684451036156162125014743550622955579737715237323508714467463047351532756224409691528642332476831673220319724437158730801472447651264708417183934709815...
output:
108 78 492 296 760 1295 1419 1 1585 92 46 399 888 745 1073 262 626 1212 338 190 971 258 950 1736 848 2 382 1804 43 1416 102 2 504 103 11 420 99 16 497 263 375 1113 1306 441 488 301 113 851 100 4 199 107 177 471 362 28 281 1108 1 1778 96 293 476 1094 538 1098 1039 63 69 706 533 1340 573 186 1381 91 9...
result:
ok correct answer! (100 test cases)