QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#670559 | #7013. Rikka with Ants | pengpeng_fudan | WA | 37ms | 3988kb | C++23 | 2.0kb | 2024-10-23 22:14:44 | 2024-10-23 22:14:45 |
Judging History
answer
#include<bits/stdc++.h>
#define double long double
using namespace std;
void solve(){
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++) cin>>a[i];
int s1,e1,s2,e2;
cin>>s1>>e1>>s2>>e2;s1--,e1--,s2--,e2--;
pair<int,int> g[4];
auto get=[&](int s1,int e1,int s2,int e2)->double {
for(int i=0;i<4;i++){
g[i]={0,0};
vector<int> lzg(n);
int t1=((i&1)?-1:1),t2=((i>>1&1)?-1:1);
for(int j=s1;j!=e1;j=(j+t1+n)%n) {
t1==1?lzg[j]++:lzg[(j-1+n)%n]++;
}
for(int j=s2;j!=e2;j=(j+t2+n)%n) {
t2==1?lzg[j]++:lzg[(j-1+n)%n]++;
}
for(int j=s1;j!=e1;j=(j+t1+n)%n) {
int w=(t1==1?(lzg[j]==2?3:1):(lzg[(j-1+n)%n]==2?3:1));
g[i].first+=w*(t1==1?a[j]:a[(j-1+n)%n]);
}
for(int j=s2;j!=e2;j=(j+t2+n)%n){
int w=(t2==1?(lzg[j]==2?3:1):(lzg[(j-1+n)%n]==2?3:1));
g[i].second+=w*(t2==1?a[j]:a[(j-1+n)%n]);
}
// cerr<<g[i].first<<' '<<g[i].second<<'\n';
}
int a0=g[0].first,a1=g[1].first,a2=g[2].first,a3=g[3].first;
if(a0-a1-a2+a3==0) {
return a2<=a3?1:0;
}
double ans=(double)(a3-a1)/(a0-a1-a2+a3);
if(ans>1) ans=1;
if(ans<0) ans=0;
return ans;
};
double q1,q2;
q1=get(s1,e1,s2,e2);
swap(s1,s2),swap(e1,e2);
q2=get(s1,e1,s2,e2);
// cerr<<q1<<' '<<q2<<"?"<<'\n';
cout<<setprecision(16)<<q2*q1*g[0].second+(1-q2)*q1*g[1].second+q2*(1-q1)*g[2].second+(1-q2)*(1-q1)*g[3].second<<' ';
cout<<setprecision(16)<<q2*q1*g[0].first+(1-q2)*q1*g[1].first+q2*(1-q1)*g[2].first+(1-q2)*(1-q1)*g[3].first<<'\n';
}
int main(){
ios::sync_with_stdio(0),cin.tie(0);
int _ = 1;
cin>>_;
while(_--) solve();
}
/*
2
5
1 5 2 4 3
1 2 3 4
5
1 5 2 4 3
1 3 2 4
*/
/*
1
5
1 5 2 4 3
1 2 3 4
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3988kb
input:
2 5 1 5 2 4 3 1 2 3 4 5 1 5 2 4 3 1 3 2 4
output:
1 2 14.66666666666667 14.66666666666667
result:
ok 2 cases
Test #2:
score: -100
Wrong Answer
time: 37ms
memory: 3812kb
input:
5000 5 8 22 47 25 13 3 5 3 1 20 9 24 41 8 23 31 48 15 46 5 17 36 29 40 36 43 34 33 29 26 16 4 15 5 3 8 22 33 1 2 2 3 26 18 44 37 21 44 44 5 15 43 44 44 37 19 10 22 14 41 37 42 18 14 34 3 17 30 42 13 2 13 15 26 31 31 41 11 35 49 13 29 33 11 27 6 16 25 47 40 2 33 27 35 35 29 48 35 5 7 17 3 13 3 26 30 ...
output:
97.07865168539326 97.07865168539326 571.6288659793814 571.6288659793814 8 22 653.32 584.64 728.8988764044944 728.8988764044944 508.2709030100334 490.5418060200669 509.9169811320755 509.9169811320755 212.8543689320388 212.8543689320388 84.26666666666667 48.53333333333333 157 99 1030.825082508251 901....
result:
wrong answer In case 1, the first value expected '72.000000000000', but found '97.078651685393', error '0.258333333333'.