CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:Shrike
Submission time:2017-10-09 19:56:39 +0300
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED25
#3ACCEPTED63
Test results
testverdicttimegroup
#1ACCEPTED0.05 s1details
#2ACCEPTED0.05 s2details
#3ACCEPTED0.04 s3details

Compiler report

input/code.cpp:30:5: warning: integer constant is so large that it is unsigned [enabled by default]
     10000000000000000000
     ^
input/code.cpp:31:1: warning: narrowing conversion of '10000000000000000000I128' from '__int128' to 'const ll {aka const long long int}' inside { } [-Wnarrowing]
 };
 ^
input/code.cpp: In function 'll dig(ll)':
input/code.cpp:39:5: warning: unused variable 'tens' [-Wunused-variable]
  ll tens;
     ^

Code

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdlib>

using namespace std;
typedef long long ll;

const ll pow_10[20] = {
    1,
    10,
    100,
    1000,
    10000,
    100000,
    1000000,
    10000000,
    100000000,
    1000000000,
    10000000000,
    100000000000,
    1000000000000,
    10000000000000,
    100000000000000,
    1000000000000000,
    10000000000000000,
    100000000000000000,
    1000000000000000000,
    10000000000000000000
};

ll
dig(ll i)
{
	ll     digits = 1U;
	ll     value  = 1U;
	ll     limit  = 9U;
	ll tens;
	if (!i--)
		return 0;
	while (i/limit >= digits) {
		const ll old_limit = limit;

		i -= digits * limit;

		digits++;
		value *= 10U;
		limit *= 10U;

		/* If limit overflows, we are in the correct, final region. */
		if (limit <= old_limit)
			break;
	}

	value += i / digits;
	value /= pow_10[(digits - 1) - (i % digits)];


	return value % 10U;
}

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];
	for (int i = 0; i < q; i++)
		cout << dig(qs[i]) << "\n";
	return 0;
}

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: ACCEPTED

input
1000
672274832941907421
260504693279721732
646999966092970935
100853063389774434
...

correct output
7
2
2
0
9
...

user output
7
2
2
0
9
...
Truncated