답안 #976038

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
976038 2024-05-06T05:47:42 Z vjudge1 Trol (COCI19_trol) C++11
30 / 50
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout); // REMBEMBER TO COMMENT THIS BEFORE SUBMITTING
    int q;
    cin >> q;
    while (q--)
    {
        ll l, r;
        cin >> l >> r;
        ll difference = r - l + 1;
        ll lmod = l % 9;
        ll rmod = r % 9;
        ll ans = 0;
        if (lmod == 0)
            lmod = 9;
        if (rmod == 0)
            rmod = 9;
        if (difference <= 9)
        {
            while (l <= r)
            {
                ans += lmod;
                lmod++;
                lmod %= 9;
                l++;
            }
        }
        else
        {

            while (lmod != (rmod + 1) % 9)
            {
                ans += lmod;
                if (lmod == 0)
                    ans += 9;
                lmod++;
                lmod %= 9;
                l++;
            }

            ans += (ll)(r - l + 1) / 9 * 45;
        }
        cout << ans << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct