CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:ISIMO66
Submission time:2017-10-07 23:44:40 +0300
Language:C++
Status:READY
Result:37
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED25
#30
Test results
testverdicttimegroup
#1ACCEPTED0.06 s1details
#2ACCEPTED0.06 s2details
#30.19 s3details

Compiler report

input/code.cpp: In function 'int main(int, char**)':
input/code.cpp:16:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
                 ^
input/code.cpp:20:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%ld", &n);
                   ^

Code

#include "stdio.h"
#include "stdlib.h"
#include <math.h>
long loc(long);
long power(int, int);
long loc10(int);
void to10nm(long, int *, long *);
void getn(long, int *);
int getnum(long);
void getlocn(long, int *);
int main(int argc, char ** argv){
int q;
scanf("%d", &q);
for (int i = 0; i < q; i++){
long int n;
scanf("%ld", &n);
printf("%d\n", getnum(n));
}
return 0;
}
long loc(long num){
int n;
long m;
to10nm(num, &n, &m);
return loc10(n) + (n+1) * m;
}
long power(int x, int n){
return (long)pow((double)x, (double)n);
}
long loc10(int n){
long sum = 0;
for (int i = n; i > 0; i--){
sum += (power(10, i-1) * i);
}
sum *= 9;
return sum;
}
void to10nm(long num, int * n, long * m){
getn(num, n);
*m = num - power(10, *n);
}
void getlocn(long num, int * n)
{
*n = -1;
for (int i = 17; i >= 0; i--)
{
if(num >= loc10(i)){
*n = i;
break;
}
}
}
void getn(long num, int * n){
for (int i = 18; i >= 0; i--){
if (num >= power(10, i)){
*n = i;
break;
}
}
}
int getnum(long pos){
int n;
getlocn(pos, &n);
double dm = ((double)pos - (double)loc10(n)) / (double)(n + 1);
long m = (long)ceil(dm);
long num = power(10, n) + m;
char * num1 = (char *)malloc(19 * sizeof(char));
sprintf(num1, "%ld", num-1);
int x = (int)num1[pos - loc(num-1) - 1] - '0';
free(num1);
return x;
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
1000
582
214
723
273
...

correct output
0
1
7
7
6
...

user output
0
1
7
7
6
...
Truncated

Test 2

Group: 2

Verdict: ACCEPTED

input
1000
615664
916441
627600
279508
...

correct output
1
2
3
2
2
...

user output
1
2
3
2
2
...
Truncated

Test 3

Group: 3

Verdict:

input
1000
672274832941907421
260504693279721732
646999966092970935
100853063389774434
...

correct output
7
2
2
0
9
...

user output
(empty)