QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395345 | #8554. Bot Friends | ucup-team052# | WA | 56ms | 4076kb | C++23 | 1.1kb | 2024-04-21 13:30:40 | 2024-04-21 13:30:42 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define SZ(x) ((int)(x).size())
#define D(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
using LL=long long;
#define N 5005
int f[N],ok[N][N],ok1[N][N],ok2[N][N];
char s[N];
int n;
void work()
{
scanf("%s",s+1); n=strlen(s+1);
for(int i=1;i<=n;i++)
{
ok1[i][i]=s[i]!='>',ok2[i][i]=s[i]!='<';
for(int j=i+1;j<=n;j++) ok1[i][j]=ok1[i][j-1]+(s[j]!='>'),ok2[i][j]=ok2[i][j-1]+(s[j]!='<');
}
auto get=[&](int l,int r,int mid)
{
int w1=ok2[l][mid],w2=ok1[mid+1][r];
if(w1>w2) swap(w1,w2);
w2=min(w1+1,w2);
return w1+w2-1;
};
for(int i=1;i<=n;i++)
{
ok[i][i]=0; int pos=i;
for(int j=i+1;j<=n;j++)
{
while(pos+1<j&&get(i,j,pos)<=get(i,j,pos+1)) pos++;
ok[i][j]=get(i,j,pos);
}
}
for(int i=1;i<=n;i++) f[i]=0;
f[0]=0;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<=n;j++) f[j]=max(f[j],f[i]+ok[i+1][j]);
}
printf("%d\n",f[n]);
}
signed main(){
#ifdef xay5421
freopen("a.in","r",stdin);
#endif
int T; cin>>T; while(T--) work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4040kb
input:
10 ?>? >?< ??<? ?><?< ?????? >?<?<>?<?< ?><???><>< ??>>><><?? <>>?>>?>?> <?<>>??<?>
output:
2 2 3 4 5 8 7 8 5 6
result:
ok 10 numbers
Test #2:
score: -100
Wrong Answer
time: 56ms
memory: 4076kb
input:
100000 >?<?<>?<?< ?><???><>< ??>>><><?? <>>?>>?>?> <?<>>??<?> >><>><<<<< >?>?>?<<>> ?><?<<?<>< ???><>?>?> <??>?<<><? ??>><?<>>> <><><?<>>? ?>>?>???>< ?<?><?<<>? >>><?<??>< ><><<>?>?< >?><>><<<? >??>?><?<> ?????<><?> <><<?<<>?< ><?>>?>?>? ?><><<<>>? ?<>?<>?<<< <><<<<<>>> ?>?>?><<>> <>?<>><>?< <<<?<>>...
output:
8 7 8 5 6 8 6 7 6 7 6 6 8 7 8 7 8 7 7 6 6 7 7 2 6 6 3 9 6 5 5 7 5 8 7 6 8 7 7 6 6 7 4 2 7 6 8 7 8 6 6 5 7 8 8 8 8 7 5 6 7 7 6 8 7 6 8 6 7 8 7 7 6 8 5 7 6 6 5 5 7 7 6 4 8 6 6 7 5 7 6 7 7 8 3 8 8 7 8 7 7 4 8 8 7 5 8 7 7 8 8 7 5 7 7 5 7 6 5 8 8 7 7 8 6 7 8 6 6 8 7 8 7 6 6 5 7 8 6 8 6 7 5 7 4 6 6 7 7 7 ...
result:
wrong answer 30th numbers differ - expected: '6', found: '5'