CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:Shrike
Submission time:2017-10-03 13:09:39 +0300
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.18 s1details
#20.03 s2details
#30.16 s3details

Code

#include <iostream>
#include <cmath>

using namespace std;
typedef long long ll;

ll
decade(ll n, ll *sum)
{
	*sum = 0;
	for (int i = 1; i < 1000000; i++) {
		if (*sum + i*9*pow(10.0, i-1) > n)
			return i;
		else
			*sum += i*9*pow(10.0, i-1);
	}
	return 0;
}
ll
nnum(ll dec, ll nth)
{
	return (ll)(pow(10.0, (int)dec-1)-1+nth);
}


int dig(int a, int b) {
	int tens [9] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 10000000 };
	return ((int)floor(a / tens[b - 1])) % 10;
 }

int
main(int argc, char **argv)
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int q;
	cin >> q;
	ll qs[q];
	for (int i = 0; i < q; i++) {
		cin >> qs[i];
		ll inth, nth, dec, s, sm, num;
		
		dec = decade(qs[i], &s);
		sm = qs[i] - s;
		nth = (ll)ceil((double)sm/(double)dec);
		num = nnum(dec, nth);
		inth = (sm-1) % dec + 1;
		cout << dig(num, inth) << "\n";
	}
	return 0;
}

Test details

Test 1

Group: 1

Verdict:

input
1000
582
214
723
273
...

correct output
0
1
7
7
6
...

user output
(empty)

Test 2

Group: 2

Verdict:

input
1000
615664
916441
627600
279508
...

correct output
1
2
3
2
2
...

user output
9
1
1
8
3
...
Truncated

Test 3

Group: 3

Verdict:

input
1000
672274832941907421
260504693279721732
646999966092970935
100853063389774434
...

correct output
7
2
2
0
9
...

user output
(empty)