답안 #976526

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
976526 2024-05-06T16:19:54 Z vjudge1 Trol (COCI19_trol) C++17
10 / 50
1 ms 348 KB
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;

ll getID(ll n) {
	return (n - 1) % 9 + 1;
}

int main() {
	//JANGAN LUPA PAKAI LONG LONG!
	ll q; cin >> q;
	while (q--) {
		ll arr[11];
		ll sub[11];
		memset(arr, 0, sizeof(arr));
		memset(sub, 0, sizeof(sub));

		ll l, r; cin >> l >> r;

		if (r <= 9) {
			ll ans = 0;
			for (ll i = l; i <= r; i++) {
				ans += i;
			}

			cout << ans << endl;
			continue;
		}

		ll sisa = r % 9;
		arr[1] += 1;
		arr[sisa + 1] -= 1;

		ll tambah = r / 9;
		arr[1] += tambah;

		for (ll i = 2; i <= 9; i++) {
			arr[i] = arr[i] + arr[i - 1];
		}

		ll sumA = 0;

		for (ll i = 1; i <= 9; i++) {
			sumA = sumA+ i * arr[i];
		}

		//sub
		ll r2 = l - 1;
		ll sisa2 = r2 % 9;
		sub[1] += 1;
		sub[sisa2 + 1] -= 1;

		tambah = (r2 - 1) / 9;
		sub[1] += tambah;

		for (ll i = 2; i <= 9; i++) {
			sub[i] = sub[i] + sub[i - 1];
		}

		ll sumB = 0;

		for (ll i = 1; i <= 9; i++) {
			sumB = sumB + i * sub[i];
		}

		cout << sumA - sumB << endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Incorrect 1 ms 348 KB Output isn't correct