Submission details
Task:Toistot
Sender:Kuha
Submission time:2025-12-20 15:27:16 +0200
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED11
#2ACCEPTED21
#3ACCEPTED31
#4ACCEPTED37
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3, 4details
#2ACCEPTED0.03 s2, 3, 4details
#3ACCEPTED0.08 s3, 4details
#4ACCEPTED0.51 s4details
#5ACCEPTED0.01 s1, 2, 3, 4details
#6ACCEPTED0.25 s4details

Compiler report

input/code.cpp: In function 'long long int f(long long int)':
input/code.cpp:27:28: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |             if (t.length() > nl) goto halve;
      |                 ~~~~~~~~~~~^~~~

Code

#include <bits/stdc++.h>

#define ll long long
#define M 1000000007

using namespace std;

//           0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17
ll coef[] = {0, 0, 1, 1, 0, 1,-1, 1, 0, 0,-1, 1, 0, 1,-1,-1, 0, 1};

ll f(ll n) {
    ll mn = 1;
    ll ans = 0;
    int nl = to_string(n).length();
    for (ll c = 2; c <= 17; c++) {
        mn *= 10;
        if (n < mn) break;
        ll x = 0;
        ll inc = n;
        while (inc > 0) {
            x += inc;
            string s = to_string(x);
            string t;
            for (int i = 0; i < c; i++) {
                t += s;
            }
            if (t.length() > nl) goto halve;
            if (stoll(t) > n) goto halve;
            goto end;
            halve:;
            x -= inc;
            inc /= 2;
            end:;
        }
        ans += coef[c] * x;
    }
    return ans;
}

int main() {
    int t;
    cin>>t;
    while (t --> 0) {
        ll l, r;
        cin>>l>>r;
        cout<<(f(r) - f(l - 1))<<endl;
    }
}

Test details

Test 1

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
1000
633 906
727 914
585 884
750 792
...

correct output
3
2
2
1
0
...

user output
3
2
2
1
0
...

Test 2

Group: 2, 3, 4

Verdict: ACCEPTED

input
1000
647761 927345
744364 840268
598715 905836
767448 810881
...

correct output
303
105
333
48
95
...

user output
303
105
333
48
95
...

Test 3

Group: 3, 4

Verdict: ACCEPTED

input
1000
663307073 949601845
762227828 860434499
613084013 927576203
785866095 830342436
...

correct output
286
98
314
44
89
...

user output
286
98
314
44
89
...

Test 4

Group: 4

Verdict: ACCEPTED

input
1000
818435896335669158 98300938101...

correct output
164737893
96015818
103821980
402263734
52636276
...

user output
164737893
96015818
103821980
402263734
52636276
...

Test 5

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
990
1 1
1 2
1 3
1 4
...

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...

Test 6

Group: 4

Verdict: ACCEPTED

input
961
1 1000000000000000000
1 999999999999999999
1 999999999999999998
1 999999999999999997
...

correct output
1001000097
1001000097
1001000096
1001000096
1001000096
...

user output
1001000097
1001000097
1001000096
1001000096
1001000096
...