# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1107398 |
2024-11-01T07:39:52 Z |
toast12 |
Trol (COCI19_trol) |
C++14 |
|
1 ms |
336 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int sum_of_digits(ll x) {
if (x/10 == 0) return x;
ll temp = 0;
while (x > 0) {
temp += x%10;
x /= 10;
}
return sum_of_digits(temp);
}
int main() {
int q;
cin >> q;
while (q--) {
ll l, r;
cin >> l >> r;
ll ans = 0;
ll start = l, end = r;
for (int i = l; (i % 10 != 0) && (i <= r); i++) {
ans += sum_of_digits(i);
start = i;
}
start++;
if (r/10 > l/10) {
for (int i = r; (i % 10 != 9) && (i >= l); i--) {
ans += sum_of_digits(i);
end = i;
}
}
if (end-start+1 >= 10) {
ans += 1ll*45*((end-start+1)/10);
ll x = sum_of_digits(start);
ll y = sum_of_digits((end-1)/10);
if (y < x) {
ans += 1ll*45-(x*(x-1)/2);
x = sum_of_digits(end);
ans += end*(end+1)/2;
}
else {
ans += y*(y+1)/2;
ans -= x*(x-1)/2;
}
}
cout << ans << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |