QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#709654#8024. FountainsdsbdsbWA 1699ms4012kbC++142.0kb2024-11-04 16:04:152024-11-04 16:04:15

Judging History

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

  • [2024-11-04 16:04:15]
  • 评测
  • 测评结果:WA
  • 用时:1699ms
  • 内存:4012kb
  • [2024-11-04 16:04:15]
  • 提交

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.9999){
		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<=3;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: 3728kb

input:

1
1

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 0
Accepted
time: 37ms
memory: 3832kb

input:

2
13 24

output:

26
13
0

result:

ok 3 number(s): "26 13 0"

Test #3:

score: 0
Accepted
time: 138ms
memory: 3916kb

input:

3
6 4 7

output:

33
21
12
8
4
0

result:

ok 6 numbers

Test #4:

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

input:

1
1000000000

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 126ms
memory: 3884kb

input:

3
1000000000 1000000000 1000000000

output:

6000000000
4000000000
3000000000
2000000000
1000000000
0

result:

ok 6 numbers

Test #6:

score: 0
Accepted
time: 366ms
memory: 3868kb

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: 365ms
memory: 3860kb

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: 367ms
memory: 4012kb

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: 366ms
memory: 3996kb

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: 365ms
memory: 3860kb

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: 366ms
memory: 3820kb

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: 361ms
memory: 3816kb

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: 858ms
memory: 3884kb

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: -100
Wrong Answer
time: 1699ms
memory: 3884kb

input:

6
993702683 956722344 945667651 937295260 920868105 928898923

output:

35868957528
28436304068
22822642178
20706312438
17869309485
15101698227
13229480240
12173997672
11217275328
10260894557
9306512942
8361186864
7415860786
6470534708
5525208630
4604340525
3683472420
2762604315
1841736210
920868105
0

result:

wrong answer 10th numbers differ - expected: '10260552984', found: '10260894557'