| Task: | Toistot |
| Sender: | Kuha |
| Submission time: | 2025-12-20 15:27:16 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 100 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 11 |
| #2 | ACCEPTED | 21 |
| #3 | ACCEPTED | 31 |
| #4 | ACCEPTED | 37 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 1, 2, 3, 4 | details |
| #2 | ACCEPTED | 0.03 s | 2, 3, 4 | details |
| #3 | ACCEPTED | 0.08 s | 3, 4 | details |
| #4 | ACCEPTED | 0.51 s | 4 | details |
| #5 | ACCEPTED | 0.01 s | 1, 2, 3, 4 | details |
| #6 | ACCEPTED | 0.25 s | 4 | details |
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 ... |
