QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#716946#5149. Best Carry PlayerMLK2WA 51ms3944kbC++141.9kb2024-11-06 16:27:292024-11-06 16:27:30

Judging History

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

  • [2024-11-06 16:27:30]
  • 评测
  • 测评结果:WA
  • 用时:51ms
  • 内存:3944kb
  • [2024-11-06 16:27:29]
  • 提交

answer

#include <bits/stdc++.h>
#define N (200000 + 10)  /*------------------ #define ------------------*/
#define M (400000 + 10)
#define MOD (1000000000 + 7)
//#define MOD (998244353)
#define INF (0x3f3f3f3f)
#define LNF (3e18)
#define mod(a,b) (((a)%(b)+(b))%(b))
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef pair<int,LL> PIL;
typedef pair<LL,int> PLI;
typedef pair<double,double> PDD;

int n;
LL a[N];

LL carry = 0;

LL add(LL x,LL y){
	LL z = 0,p = 0,c = 0;
	while(x || y){
		LL x0 = x % 10,y0 = y % 10;
		if(x0 + y0 + c >= 10){
			carry ++ ;
			z += pow(10,p) * (x0 + y0 + c - 10);
			c = 1;
		}else{
			c = 0;
			z += pow(10,p) * (x0 + y0 + c);
		}
		x /= 10,y /= 10,p ++ ;
	}
	if(c){
		z += pow(10,p) * c;
	}
	return z;
}

LL calc(){
	carry = 0;
	LL z = 0;
	for(int i = 1;i <= n;i ++ ) z = add(z,a[i]);
	return carry;
}

LL ac_ans = 2e9;

int m;
vector<int> path;
void dfs(int u,int state){
	if(u == m + 1){
		carry = 0;
		LL z = 0;
		for(int v : path){
			z = add(z,a[v]);
		}
		ac_ans = min(ac_ans,carry);
		return;
	}
	for(int i = 1;i <= m;i ++ )
		if(!(state >> i & 1)){
			path.push_back(i);
			dfs(u + 1,state | (1 << i));
			path.pop_back();
		}
}

auto solve(){
	
	cin >> n;
	m = n;
	for(int i = 1;i <= n;i ++ ) cin >> a[i];
	
	// dfs(1,0);
	
	sort(a + 1,a + 1 + n);
	int ans1 = calc();
	
	sort(a + 1,a + 1 + n,greater<int>());
	int ans2 = calc();
	
	cout << min(ans1,ans2) << '\n';
	
	// if(min(ans1,ans2) == ac_ans){
		// cout << "Accept\n";
	// }else{
		// cout << "WA\n";
	// }
	
}

signed main(){
	IOS
	int T = 1;
	//
	cin >> T;
	while(T -- ) solve();
	//while(T -- ) cout << (solve() ? "YES" : "NO") << '\n';

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3
9 99 999
1
12345

output:

5
0

result:

ok 2 number(s): "5 0"

Test #2:

score: 0
Accepted
time: 46ms
memory: 3876kb

input:

100000
1
481199252
1
634074578
1
740396295
1
579721198
1
503722503
1
202647942
1
268792718
1
443917727
1
125908043
1
717268783
1
150414369
1
519096230
1
856168102
1
674936674
1
274667941
1
527268921
1
421436316
1
286802932
1
646837311
1
451394766
1
105650419
1
302790137
1
254786900
1
76141081
1
7393...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 numbers

Test #3:

score: -100
Wrong Answer
time: 51ms
memory: 3944kb

input:

10000
10
598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754 223219513
10
312183499 905549873 673542337 566661387 879397647 434495917 631413076 150918417 579868000 224422012
10
525305826 535526356 404334728 653535984 998133227 879226371 59632864 356493387 62611196...

output:

39
39
38
33
40
30
42
38
36
41
31
39
41
36
36
38
37
39
36
37
37
40
36
42
38
38
35
44
35
39
35
40
39
39
36
34
47
39
40
33
43
40
46
35
35
40
37
37
38
33
33
43
38
43
34
39
39
34
34
43
36
35
36
40
42
43
39
40
38
39
35
40
38
43
38
38
41
40
40
35
37
41
32
41
40
38
42
35
37
42
39
33
36
38
39
39
41
41
30
35
...

result:

wrong answer 1st numbers differ - expected: '42', found: '39'