Submission #13687784
Source Code Expand
#include <bits/stdc++.h>
#define LL long long
#define db long double
using namespace std;
template <typename T> void read(T &x){
x = 0; int f = 1; char ch = getchar();
while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }
const int N = 200050;
int n; LL a[N],b[N],tmp[N],preb[N],prebi[N];
inline void init(){
int i,id = 1;
read(n);
for (i = 1; i <= n; ++i) read(a[i]);
for (i = 1; i <= n; ++i) read(b[i]);
for (i = 1; i <= n; ++i) if (a[i] > a[id]) id = i;
if (id != 1){
--id;
for (i = 1; i <= n; ++i) tmp[i] = a[i];
for (i = 1; i <= n; ++i) a[(i<=id?i+n-id:i-id)] = tmp[i];
for (i = 1; i <= n; ++i) tmp[i] = b[i];
for (i = 1; i <= n; ++i) b[(i<=id?i+n-id:i-id)] = tmp[i];
}
a[n+1] = a[1],b[n+1] = b[1];
a[0] = a[n],b[0] = b[n];
for (i = 1; i <= n+1; ++i) preb[i] = preb[i-1] + b[i],prebi[i] = prebi[i-1] + b[i] * i;
}
inline db calc(int l,int r,int m){
if (l == r) return a[l];
db k = r-l,b = (db)(2.0) * (r) * (preb[r-1]-preb[l]) - (db)(2.0) * (prebi[r-1] - prebi[l]),y = a[r] - a[l],x = (y - b) / k;
return a[l] + (m-l) * x + (db)(2.0) * (m) * (preb[m-1]-preb[l]) - (db)(2.0) * (prebi[m-1] - prebi[l]);
}
int stk[N],top; db ans,mx[N];
int main(){
init();
int i,j,ll,rr;
stk[0] = 1;
for (i = 1; i <= n+1; ++i){
while (top && calc(stk[top-1],i,stk[top]) >= calc(stk[top-1],stk[top],stk[top])) --top;
stk[++top] = i;
}
for (i = 0; i <= top; ++i){
ll = stk[i],rr = stk[i+1];
for (j = ll; j <= rr && j <= n; ++j) mx[j] = max(mx[j],calc(ll,rr,j));
}
for (i = 1; i <= n; ++i) ans += mx[i];//,cerr << i << ' ' << mx[i] << '\n';
ans /= n;
cout << fixed << setprecision(20) << ans << '\n';
return 0;
}
Submission Info
| Submission Time |
|
| Task |
E - Random Pawn |
| User |
srf |
| Language |
C++ (GCC 9.2.1) |
| Score |
1300 |
| Code Size |
1843 Byte |
| Status |
AC |
| Exec Time |
36 ms |
| Memory |
15388 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
1300 / 1300 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example0.txt, example1.txt, example2.txt, example3.txt |
| All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, example0.txt, example1.txt, example2.txt, example3.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 000.txt |
AC |
2 ms |
3588 KiB |
| 001.txt |
AC |
2 ms |
3684 KiB |
| 002.txt |
AC |
36 ms |
14644 KiB |
| 003.txt |
AC |
32 ms |
14508 KiB |
| 004.txt |
AC |
10 ms |
6124 KiB |
| 005.txt |
AC |
15 ms |
6104 KiB |
| 006.txt |
AC |
30 ms |
14752 KiB |
| 007.txt |
AC |
11 ms |
6436 KiB |
| 008.txt |
AC |
11 ms |
6332 KiB |
| 009.txt |
AC |
32 ms |
14968 KiB |
| 010.txt |
AC |
30 ms |
15364 KiB |
| 011.txt |
AC |
33 ms |
15192 KiB |
| 012.txt |
AC |
30 ms |
14944 KiB |
| 013.txt |
AC |
31 ms |
15100 KiB |
| 014.txt |
AC |
32 ms |
15388 KiB |
| 015.txt |
AC |
32 ms |
15248 KiB |
| example0.txt |
AC |
8 ms |
3580 KiB |
| example1.txt |
AC |
2 ms |
3784 KiB |
| example2.txt |
AC |
2 ms |
3584 KiB |
| example3.txt |
AC |
2 ms |
3784 KiB |