CSES - HIIT Open 2016 - Results
Submission details
Task:Cent saving
Sender:Spitfire
Submission time:2016-05-28 14:54:57
Language:C++
Status:READY
Result:
Test results
testverdicttime
#10.06 sdetails
#20.06 sdetails

Code

#include <iostream>
#include <cstdint>
inline unsigned int round(unsigned int n, unsigned int d) {
	switch(d) {
		case 0:
		case 1:
		case 2:
			return (n / 10) * 10;

		case 3:
		case 4:
		case 5:
		case 6:
		case 7:
			return (n / 10) * 10 + 5;
		case 8:
		case 9:
			return (n / 10) * 10 + 10;
	}
	return 0;
}
inline bool is_cheap(unsigned int n) {
	switch(n) {
		case 0:
		case 1:
		case 2:
		case 5:
		case 6:
		case 7:
			return true;
	}
	return false;
}

int main()
{
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(0);

	unsigned int t;
	std::cin >> t;

	unsigned int nb;
	for (size_t i = 0; i < t; i++) {
		std::cin >> nb;
		unsigned int input;
		unsigned int digit;
		uint64_t sum = 0;
		uint64_t temp_sum = 0;
		for (size_t j = 0; j < nb; j++) {
			std::cin >> input;
			digit = input % 10;
			if (is_cheap(digit)) {
				sum += round(input, digit);
				continue;
			}
			temp_sum += input;
			digit = temp_sum % 10;
			if (is_cheap(digit)) {
				sum += round(temp_sum, digit);
				temp_sum = 0;
			}
		}
		digit = temp_sum % 10;
		sum += round(temp_sum, digit);
		std::cout << sum << std::endl;
	}

	return 0;
}

Test details

Test 1

Verdict:

input
100
1000
528433894 255789530 559301042 ...

correct output
475191144965
460688647850
478543444030
475238936090
456736521510
...

user output
475191145085
460688647960
478543444145
475238936190
456736521630
...

Test 2

Verdict:

input
1
100000
666086355 190481330 514353517 ...

correct output
47176864928795

user output
47176864939695