QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#838 | #573261 | #9314. The Median of the Median of the Median | Loxilante | 1926406757 | Success! | 2024-09-18 18:08:04 | 2024-09-18 18:08:05 |
Details
Extra Test:
Wrong Answer
time: 0ms
memory: 3912kb
input:
10 11 9 13 12 9 3 2 3 11 1
output:
3
result:
wrong answer 1st numbers differ - expected: '9', found: '3'
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#573261 | #9314. The Median of the Median of the Median | 1926406757 | WA | 282ms | 35308kb | C++17 | 1.7kb | 2024-09-18 17:57:03 | 2024-09-18 18:15:13 |
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define no cout<<"No"<<endl
#define yes cout<<"Yes"<<endl
#define endl '\n'
// #define x first
// #define y second
typedef pair<int,int> PII;
const int N=2010;
const int mod=998244353;
const int INF=0x3f3f3f3f3f3f3f3f;
int b[N][N];
void solve(){
int n;cin>>n;
vector<int>a(n+1);
for(int i=1;i<=n;i++){
cin>>a[i];
}
vector<int>pre(n+1);
auto check=[&](int mid){
for(int i=1;i<=n;i++)pre[i]=pre[i-1]+(a[i]<=mid?1:0);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
b[i][j]=0;
}
}
for(int l=1;l<=n;l++){
for(int r=l;r<=n;r++){
if(pre[r]-pre[l-1]>=(r-l+2)/2)b[l][r]=1;
else b[l][r]=0;
}
}
for(int i=n;i>=1;i--){
for(int j=i;j>=1;j--){
b[j][i]+=b[j+1][i];
}
}
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
b[i][j]+=b[i][j-1];
}
}
int cnt=0;
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
if(b[i][j]>=((j-i+2)*(j-i+1)/2+1)/2)cnt++;
}
}
if(cnt>=(n*n/2+1)/2)return 1;
return 0;
};
int l=0,r=1e9;
while(l+1!=r){
int mid=l+r>>1;
if(check(mid))r=mid;
else l=mid;
}
cout<<r<<endl;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int _=1;
while(_--)solve();
return 0;
}