Submission #231136

# Submission time Handle Problem Language Result Execution time Memory
231136 2020-05-12T20:42:58 Z jungsnow Trol (COCI19_trol) C++14
50 / 50
5 ms 384 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

ll L, R;

void solve() {
    cin >> L >> R;
    ll mi[9];
    for (int i = 0; i < 9; i++) mi[i] = 2e18;
    for (int i = 0; i < 10; i++) {
        ll nVal = (L + i);
        if (nVal > R) break;
        mi[nVal % 9] = min(mi[nVal % 9], nVal);
    }
    ll sum = 0;
    for (int i = 0; i < 9; i++) {
        if (mi[i] == 2e18) continue;
        //cerr<<i<<' '<<mi[i]<<'\n';
        ll cnt = (R - mi[i]) / 9 + 1;
        if (i == 0) sum += 9 * cnt;
        else sum += i * cnt;
    }
    cout << sum << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int T; cin >> T; while (T--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct