QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#39837#4355. SeesawZeinDaner#0 1ms5964kbC++1.4kb2022-07-14 04:26:092024-05-26 01:00:55

Judging History

你现在查看的是最新测评结果

  • [2024-05-26 01:00:55]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:5964kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-14 04:26:09]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<double,double> dd;
const int MAX_N=2e5+10;
const int MAX=1e9+10;
ll val[MAX_N];
ll prs[MAX_N];

dd minmax(int l,int r){
  if(l==r) return dd(val[l],val[l]);
  double c=prs[r]-prs[l-1];
  c/=(double)(r-l+1);
  dd tl=minmax(l+1,r);
  tl.first=min(tl.first,c); tl.second=max(tl.second,c);
  dd tr=minmax(l,r-1);
  tr.first=min(tr.first,c); tr.second=max(tr.second,c);
  if(tl.second-tl.first<tr.second-tr.first) return tl;
  return tr;
}
int main(){
  int n; cin>>n;
  for(int i=1;i<=n;i++){
    cin>>val[i];
  }
  for(int i=1;i<=n;i++){
    prs[i]=prs[i-1]+val[i];
  }
  double pr=prs[n]/(double)n;
  double ans=MAX;
  for(int j=1;j<=n;j++){
    double mi=min(pr,(double)val[j]),ma=max(pr,(double)val[j]);
    int l=1,r=n;
    ll s=prs[n];
    for(int i=1;i<n;i++){
      double dl=(s-val[l])/(double)(n-i);
      double dr=(s-val[r])/(double)(n-i);
      if(l==j){
	mi=min(mi,dr); ma=max(ma,dr);
	s-=val[r];
	r--;
	continue;
      }
      if(r==j){
	mi=min(mi,dl); ma=max(ma,dl);
	s-=val[l];
	l++;
	continue;
      }
      if(min(abs(dl-ma),abs(dl-mi))>min(abs(dr-ma),abs(dr-mi))){
	mi=min(mi,dr); ma=max(ma,dr);
	s-=val[r];
	r--;
      }
      else{
	mi=min(mi,dl); ma=max(ma,dl);
	s-=val[l];
	l++;
      }
    }
    ans=min(ans,ma-mi);
  }
  printf("%.12f\n",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 1
Accepted
time: 1ms
memory: 5856kb

input:

2
925278587 966813970

output:

20767691.500000000000

result:

ok found '20767691.500000000', expected '20767691.500000000', error '0.000000000'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

20
7902238 121690240 160345001 255257832 269315023 288280211 296247186 353929891 494812700 530994847 567379029 567478415 612943598 644028258 654380821 696407711 708542915 738196686 743020754 760907139

output:

52991294.166666686535

result:

ok found '52991294.166666687', expected '52991294.166666687', error '0.000000000'

Test #3:

score: -1
Wrong Answer
time: 1ms
memory: 5964kb

input:

20
37698309 122861191 172244451 227579326 314637638 425599056 429200117 531049382 548293537 557767688 600249369 625965962 703410128 707452380 747227710 753853272 821738507 858449772 859150731 988518805

output:

71345889.375000000000

result:

wrong answer 1st numbers differ - expected: '37041534.6529411', found: '71345889.3750000', error = '0.9261051'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%