QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#709540#8024. FountainsdsbdsbWA 333ms4112kbC++142.0kb2024-11-04 15:19:422024-11-04 15:19:44

Judging History

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

  • [2024-11-04 15:19:44]
  • 评测
  • 测评结果:WA
  • 用时:333ms
  • 内存:4112kb
  • [2024-11-04 15:19:42]
  • 提交

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);
	sz[0]=v[0].size();
	sz[1]=v[1].size();
//	printf("%lld\n",calc());
	for(double T=2e8;T>1;T*=0.9995){
		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 i=1;i<n*(n+1)/2;i++){
		int cnt=0;
		memset(l,0,sizeof l);
		for(int j=11;j<=99;j++){
			if(j%10>n||j%10<j/10) continue;
			v[0].pb(j);
		}
		for(int j=11;j<=99;j++){
			if(j%10>n||j%10<j/10) continue;
			cnt++;
			l[j]=1;
			v[1].pb(j);
			v[0].erase(lb(v[0],j));
			if(cnt==i) break;
		}
//		printf("%d %d !\n",v[0].size(),v[1].size());
		ans=1e18;
		for(int j=1;j<=3;j++) SA();
		cout<<ans<<endl;
		vector<int>().swap(v[0]);
		vector<int>().swap(v[1]);
	}
	cout<<0;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3668kb

input:

1
1

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 0
Accepted
time: 8ms
memory: 3948kb

input:

2
13 24

output:

26
13
0

result:

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

Test #3:

score: 0
Accepted
time: 28ms
memory: 3920kb

input:

3
6 4 7

output:

33
21
12
8
4
0

result:

ok 6 numbers

Test #4:

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

input:

1
1000000000

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 26ms
memory: 3828kb

input:

3
1000000000 1000000000 1000000000

output:

6000000000
4000000000
3000000000
2000000000
1000000000
0

result:

ok 6 numbers

Test #6:

score: 0
Accepted
time: 78ms
memory: 3984kb

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: 69ms
memory: 3924kb

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: 72ms
memory: 3928kb

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: 72ms
memory: 3924kb

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: 73ms
memory: 3952kb

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: 72ms
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: 72ms
memory: 3864kb

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: 170ms
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: 333ms
memory: 4112kb

input:

6
993702683 956722344 945667651 937295260 920868105 928898923

output:

35868957528
28436304068
22822642178
20706312438
17869309485
15101698227
13232845688
12173997672
11217275328
10263576859
9306854515
8361186864
7415860786
6470534708
5525208630
4604340525
3683472420
2762604315
1841736210
920868105
0

result:

wrong answer 7th numbers differ - expected: '13229480240', found: '13232845688'