QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#604196#9412. Stop the Castlezhk88719WA 43ms35084kbC++141.1kb2024-10-02 01:09:492024-10-02 01:09:50

Judging History

This is the latest submission verdict.

  • [2024-10-02 01:09:50]
  • Judged
  • Verdict: WA
  • Time: 43ms
  • Memory: 35084kb
  • [2024-10-02 01:09:49]
  • Submitted

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;
}

詳細信息

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)