QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#384193 | #3701. Necklace | NYOJ-2 | WA | 0ms | 4012kb | C++17 | 1.8kb | 2024-04-09 20:56:22 | 2024-04-09 20:56:23 |
Judging History
answer
#include<cstdio>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
using namespace std;
const int nn = 110000;
const int inf = 0x3fffffff;
int n;
int a[nn];
int c[nn*2];
int f1[nn],f2[nn];
int tree[11000];
inline int lowbit(int x)
{
return x&(-x);
}
int getmax(int id)
{
int re=0;
while(id>0)
{
re=max(re,tree[id]);
id-=lowbit(id);
}
return re;
}
void add(int id,int val)
{
if(id==0)
return ;
for(int i=id;i<=10000;i+=lowbit(i))
{
tree[i]=max(tree[i],val);
}
}
int solve(int id)
{
int i;
f1[0]=0;
for(i=1;i<=10000;i++)
tree[i]=0;
int tem;
for(i=id+1;i<id+n;i++)
{
if(c[i]==10000)
{
f1[i-id]=f1[i-id-1];
continue;
}
tem=getmax(c[i])+c[i];
f1[i-id]=max(f1[i-id-1],tem);
add(c[i],tem);
}
f2[n]=0;
for(i=1;i<=10000;i++)
tree[i]=0;
for(i=id+n-1;i>=id+1;i--)
{
if(c[i]==10000)
{
f2[i-id]=f2[i-id+1];
continue;
}
tem=getmax(c[i])+c[i];
f2[i-id]=max(f2[i-id+1],tem);
add(c[i],tem);
}
int re=0;
for(i=0;i<=n-1;i++)
re=max(re,f1[i]+f2[i+1]);
return re;
}
int ve[20],lv;
int main()
{
int i;
while(scanf("%d",&n)!=EOF)
{
lv=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
c[i]=a[i];
c[i+n]=a[i];
if(a[i]==10000)
ve[lv++]=i;
}
int ans=0;
for(i=0;i<lv;i++)
{
ans=max(ans,solve(ve[i]));
}
printf("%d\n",ans+10000);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3956kb
input:
6 10000 3 2 4 2 3
output:
10010
result:
ok 1 number(s): "10010"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
2 10000 10000
output:
10000
result:
ok 1 number(s): "10000"
Test #3:
score: 0
Accepted
time: 0ms
memory: 4012kb
input:
1 10000
output:
10000
result:
ok 1 number(s): "10000"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3868kb
input:
100 5 2 7 8 4 2 4 6 2 3 3 3 6 9 0 7 5 5 8 8 1 8 5 1 9 5 0 0 5 9 5 9 4 7 8 6 9 5 10000 3 0 5 3 9 3 7 7 5 7 5 0 0 8 6 1 7 1 0 4 4 4 6 2 6 8 7 2 0 1 9 8 3 6 4 5 0 0 2 5 1 0 1 5 5 3 4 3 1 6 7 0 5 7 5 3 1 4 0 6 9
output:
10150
result:
wrong answer 1st numbers differ - expected: '10182', found: '10150'