Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

who was wrong i think may be me...

Правка en1, от Ertugrul_, 2021-02-22 04:51:48

in cses online judge a introductory catagory problem digit queries (http://https://cses.fi/problemset/task/2431) when i submit this problem solutin i got wrong answer in test case 3 , 4 . I think you know guys cses online judge provided test case like codeforces . so I want to test it locally , Unfortunately i noticed that in test case 4 in codeforces compiler and my pc found output 6 for input 158888888888888841 but, in cses show user output 7. my solution is correct or wrong it's not problem why two place this two different output. what should be the problem....

input: 1 158888888888888841

cses output: 7

codeforces and my pc output: 6

this is my code :

include <bits/stdc++.h>

using namespace std;

signed main() { ios_base::sync_with_stdio(0); cin.tie(0);

long long q, cur = 0, t = 1 ; 
vector <long long> pre ; 
pre.push_back(0) ; 
for (long long l = 1, r = 10,c=1 ; cur < 1e18 ; l *= 10, r*= 10,c++) {
    pre.push_back((r-l)*c) ; 
    cur += (r-l)*c ; 
    ++t ; 
} 
for (int i=1;i<t;++i) pre[i] += pre[i-1] ; 
cin >> q ; 
while (q--) {
    long long nth ; 
    cin >> nth ; 
    int x = lower_bound(pre.begin(), pre.end(), nth) - pre.begin() ; 
    if (pre[x] > nth) x-- ; 
    if (pre[x] == nth) { 
        cout << 9 << endl ; 
        continue ; 
    } 
    long long dif = nth - pre[x], digit = x+1 ; 
    long long num = pow(10, digit-1) - 1 + (dif-1)/digit ; 
    dif = dif - (dif-1)/digit * digit ; 
    num++ ; 
    int a[digit] = {}, i = digit-1 ; 
    while (num > 0) {
        a[i--] = num%10 ; 
        num /= 10 ; 
    }
    cout << a[dif-1] << endl ; 
}

return 0;

}

Теги pllk

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en6 Английский Ertugrul_ 2021-02-22 06:28:23 7 Tiny change: 'e :\n\n```cpp#include <' -> 'e :\n\n```#include <'
en5 Английский Ertugrul_ 2021-02-22 06:26:00 3 Tiny change: 'e :\n\n```cpp#include <' -> 'e :\n\n```#include <'
en4 Английский Ertugrul_ 2021-02-22 06:25:39 9
en3 Английский Ertugrul_ 2021-02-22 04:59:13 5
en2 Английский Ertugrul_ 2021-02-22 04:54:35 35 Tiny change: 'rn 0;\n}\n' -> 'rn 0;\n}\n\n// sorry for my poor english...\n'
en1 Английский Ertugrul_ 2021-02-22 04:51:48 1832 Initial revision (published)