結果

問題 No.297 カードの数式
ユーザー FF256grhyFF256grhy
提出日時 2015-11-07 00:37:47
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,039 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 26,468 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 22:49:17
合計ジャッジ時間 1,132 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int n, v[12];
char c[15];

int main(void) {
	scanf("%d", &n);
	int i, j;
	for(i = 0; i < n; i++) {
		scanf(" %c", &c[i]);
		if('0' <= c[i] && c[i] <= '9') { v[ c[i] - '0' ]++; }
		else {
			if(c[i] == '+') { v[10]++; } else { v[11]++; }
		}
	}
	
	long long int large = 0;
	int counter = 0, d = n - 2 * (v[10] + v[11]);
	int max_p = 0, max_m = 0;
	int min_p = 0, min_m = 0;
	for(i = 9; 0 <= i; i--) {
	for(j = 0; j < v[i]; j++) {
		if(counter < d) {
			large = 10 * large + i;
		} else {
			if(counter < d + v[10]       ) { max_p += i; } else { max_m += i; }
			if(counter < d + (v[11] - 1) ) { min_m += i; } else { min_p += i; }
		}
		counter++;
	}
	}
	
	long long int max = max_p - max_m + large;
	long long int min = min_p - min_m - large;
	
	if(v[11] == 0) {
		int sum = 0, base = 1;
		counter = 0;
		for(i = 9; 0 <= i; i--) {
		for(j = 0; j < v[i]; j++) {
			sum += i * base;
			counter++;
			if(counter % (v[10] + 1) == 0) { base *= 10; }
		}
		}
		min = sum;
	}
	
	printf("%lld %lld\n", max, min);
	
	return 0;
}
0