Code Submission Evaluation System Login

CSES - HIIT Open 2016

HIIT Open 2016

Contest start:2016-05-28 11:00:00
Contest end:2016-05-28 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2016-05-28 15:09:37
2016-05-28 14:54:57
Task:Cent saving
Sender:Spitfire
Submission time:2016-05-28 15:09:37
Status:READY
Result:WRONG ANSWER

Show test data

Code

#include <iostream>
#include <cstdint>
inline uint64_t round(uint64_t n, uint64_t 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(uint64_t 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;
		uint64_t input;
		uint64_t 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;
}