QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#709593 | #8024. Fountains | dsbdsb | WA | 2108ms | 4088kb | C++14 | 2.0kb | 2024-11-04 15:40:29 | 2024-11-04 15:40:35 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define N 13
#define lb(t,i) lower_bound(t.begin(),t.end(),i)
using namespace std;
int n,l[N*N],imx=((1ll<<31)-1),sz[2];
ll s[N],ans,cur;
vector<int> ve[N*N],v[2];
mt19937 rng(time(0));
inline int rd(){
return rng()&imx;
}
bool cmp(int aa,int bb){
return s[aa%10]-s[aa/10-1]>s[bb%10]-s[bb/10-1];
}
inline ll val(int ss){
return s[ss%10]-s[ss/10-1];
}
inline ll calc(){
ll rt=0;
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
rt+=s[j]-s[i-1];
// printf("+ %d %d %lld\n",i,j,s[j]-s[i-1]);
for(auto g:ve[10*i+j]) if(l[g]){
rt-=val(g);
// printf("- %lld\n",val(g));
break;
}
}
}
return rt;
}
void SA(){
cur=calc();
ans=min(ans,cur);
// printf("!!!\n");
sz[0]=v[0].size();
sz[1]=v[1].size();
// printf("%lld\n",calc());
for(double T=2e9;T>10;T*=0.9998){
int i=rd()%sz[0],j=rd()%sz[1];
swap(v[0][i],v[1][j]);
// printf("%.3f %d %d %lld\n",T,v[0][i],v[1][j],calc());
swap(l[v[0][i]],l[v[1][j]]);
ll fz=calc();
if(fz<=cur){
cur=fz;
ans=min(ans,cur);
continue;
}
if(exp((double)(fz-cur)/T)>(double)rd()/imx) cur=fz;
else swap(v[0][i],v[1][j]),swap(l[v[0][i]],l[v[0][j]]);
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++) cin>>s[i],s[i]+=s[i-1];
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
for(int k=i;k<=j;k++){
for(int o=k;o<=j;o++){
ve[i*10+j].pb(k*10+o);
}
}
sort(ve[i*10+j].begin(),ve[i*10+j].end(),cmp);
}
}
for(int j=11;j<=99;j++){
if(j%10>n||j%10<j/10) continue;
v[0].pb(j);
}
for(int i=1;i<n*(n+1)/2;i++){
sort(v[1].begin(),v[1].end());
sort(v[0].begin(),v[0].end());
for(int j=11;j<=99;j++) if(!l[j]){
if(j%10>n||j%10<j/10) continue;
l[j]=1;
v[1].pb(j);
v[0].erase(lb(v[0],j));
break;
}
// printf("%d %d !\n",v[0].size(),v[1].size());
ans=1e18;
for(int j=1;j<=4;j++) SA();
cout<<ans<<endl;
}
cout<<0;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3732kb
input:
1 1
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 21ms
memory: 3952kb
input:
2 13 24
output:
26 13 0
result:
ok 3 number(s): "26 13 0"
Test #3:
score: 0
Accepted
time: 93ms
memory: 3884kb
input:
3 6 4 7
output:
33 21 12 8 4 0
result:
ok 6 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
1 1000000000
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 83ms
memory: 3888kb
input:
3 1000000000 1000000000 1000000000
output:
6000000000 4000000000 3000000000 2000000000 1000000000 0
result:
ok 6 numbers
Test #6:
score: 0
Accepted
time: 246ms
memory: 3952kb
input:
4 91 24 13 45
output:
402 267 185 137 89 52 39 26 13 0
result:
ok 10 numbers
Test #7:
score: 0
Accepted
time: 243ms
memory: 3944kb
input:
4 41 38 27 23
output:
386 279 220 168 130 92 69 46 23 0
result:
ok 10 numbers
Test #8:
score: 0
Accepted
time: 243ms
memory: 3908kb
input:
4 96 79 21 85
output:
799 544 386 276 180 84 63 42 21 0
result:
ok 10 numbers
Test #9:
score: 0
Accepted
time: 245ms
memory: 4000kb
input:
4 64 14 13 21
output:
246 178 124 96 74 52 39 26 13 0
result:
ok 10 numbers
Test #10:
score: 0
Accepted
time: 244ms
memory: 3996kb
input:
4 37 39 74 87
output:
691 465 374 296 222 148 111 74 37 0
result:
ok 10 numbers
Test #11:
score: 0
Accepted
time: 240ms
memory: 4008kb
input:
4 13 81 35 93
output:
634 378 192 122 87 52 39 26 13 0
result:
ok 10 numbers
Test #12:
score: 0
Accepted
time: 243ms
memory: 4000kb
input:
4 99 79 63 38
output:
832 582 436 310 231 152 114 76 38 0
result:
ok 10 numbers
Test #13:
score: 0
Accepted
time: 570ms
memory: 3984kb
input:
5 960291817 979089901 937338124 900872248 921429110
output:
21385776793 16901343929 13964074226 11201545674 9358687454 8338338015 7378046198 6420151212 5462256226 4504361240 3603488992 2702616744 1801744496 900872248 0
result:
ok 15 numbers
Test #14:
score: 0
Accepted
time: 1122ms
memory: 4088kb
input:
6 993702683 956722344 945667651 937295260 920868105 928898923
output:
35868957528 28436304068 22822642178 20706312438 17869309485 15101698227 13229480240 12173997672 11217275328 10260552984 9306512942 8361186864 7415860786 6470534708 5525208630 4604340525 3683472420 2762604315 1841736210 920868105 0
result:
ok 21 numbers
Test #15:
score: -100
Wrong Answer
time: 2108ms
memory: 3888kb
input:
7 945176955 913718431 912448136 950992979 912981052 948181396 946164955
output:
53191717275 44501626672 37196960404 30994801907 28115745758 25262766821 22420682553 20530328643 18599249427 16741635941 15719697753 14736074159 13790819372 12847195007 11899477462 10959663982 10040331455 9126613024 8213099056 7300118004 6387136952 5474688816 4562240680 3649792544 2737344408 18248962...
result:
wrong answer 8th numbers differ - expected: '20464902679', found: '20530328643'