QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#604196 | #9412. Stop the Castle | zhk88719 | WA | 43ms | 35084kb | C++14 | 1.1kb | 2024-10-02 01:09:49 | 2024-10-02 01:09:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=2005;
int n,cnt;
int ans[N],a[N],b[N][N],c[N][N];
bool check(int x)
{
// cout<<x<<" "<<endl;
for(int i=1;i<=n;i++)
a[i]=a[i-1]+(ans[i]<=x?1:-1);
memset(b,0,sizeof b);
memset(c,0,sizeof c);
for(int i=1;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
b[i][j]=(a[j]-a[i-1]>=0?1:-1);
}
}
int res=0;
for(int i=n;i>0;i--)
{
for(int j=i;j<=n;j++)
{
c[i][j]=c[i][j-1]+c[i+1][j]-c[i+1][j-1]+b[i][j];
if(c[i][j]-c[i][j-1]-c[i+1][j]+c[i+1][j-1]>=0)
res++;
}
}
if(res>=cnt)
return true;
return false;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
cin>>n;
cnt=(n*(n+1)/2)/2;
for(int i=1;i<=n;i++) cin>>ans[i];
int l=1,r=1e9;
while(l<r)
{
int mid=(l+r)/2;
if(check(mid))
r=mid;
else l=mid+1;
}
cout<<l<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 43ms
memory: 35084kb
input:
4 7 1 3 6 6 4 7 2 1 6 3 4 1 2 6 3 3 4 6 4 3 1 2 1 1 2 2 0 3 1 1 1 3 3 3 1 1 2 3 1 1 1 3 2 3 0
output:
3
result:
wrong output format Unexpected end of file - int32 expected (test case 1)