# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
218199 | maskoff | Trol (COCI19_trol) | C++14 | 1095 ms | 384 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/rope>
#define file ""
#define all(x) x.begin(), x.end()
#define sc second
#define fr first
#define pb push_back
#define mp make_pair
using namespace std;
using namespace __gnu_cxx;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const int inf = 1e9;
const int MOD = 998244353;
const int N = 5e5;
const int dx[] = {+1, -1, 0, 0};
const int dy[] = {0, 0, +1, -1};
ll sum(ll x) {
ll res = 0;
while (x) {
res += x % 10;
x /= 10 ;
}
return res;
}
ll get(ll x) {
while (x >= 10) {
x = sum(x);
}
return x;
}
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(NULL);
srand(time(NULL));
int q;
cin >> q;
while (q--) {
ll l, r;
cin >> l >> r;
ll ans = (r - l + 1) / 9;
ans *= 45;
if (ans == 0) {
for (int i = l; i <= r; i++)
ans += get(i);
cout << ans << endl;
continue;
}
l = get(l);
r = get(r);
if (l != 1)
for (int i = l; i <= 9; i++)
ans += i;
if (r != 9)
for (int i = 1; i <= r; i++)
ans += i;
cout << ans << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |