CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:Nanohenry
Submission time:2017-10-15 21:13:21 +0300
Language:C++
Status:READY
Result:37
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED25
#30
Test results
testverdicttimegroup
#1ACCEPTED0.06 s1details
#2ACCEPTED0.27 s2details
#3--3details

Code

#include <iostream>
#include <bits/stdc++.h>

#define dt uint64_t

// uint64_t -> 64 bit variables
// Max value: ~9000000000000000000

using namespace std;

inline dt getDigits(dt value) {
    if (value < 10) {
    	return 1;
    } else if (value < 100) {
    	return 2;
    } else if (value < 1000) {
    	return 3;
    } else if (value < 10000) {
    	return 4;
    } else if (value < 100000) {
    	return 5;
    } else if (value < 1000000) {
    	return 6;
    } else if (value < 10000000) {
    	return 7;
    } else if (value < 100000000) {
    	return 8;
    } else if (value < 1000000000) {
    	return 9;
    } else if (value < 10000000000) {
    	return 10;
    } else if (value < 100000000000) {
    	return 11;
    } else if (value < 1000000000000) {
    	return 12;
    } else if (value < 10000000000000) {
    	return 13;
    } else if (value < 100000000000000) {
    	return 14;
    } else if (value < 1000000000000000) {
    	return 15;
    } else if (value < 10000000000000000) {
    	return 16;
    } else if (value < 100000000000000000) {
    	return 17;
    } else if (value < 1000000000000000000) {
    	return 18;
    }
    return 19;
}

inline dt getDiv(dt value) {
	if (value == 0) {
		return 0;
	} else if (value == 1) {
		return 1;
	} else if (value == 2) {
		return 10;
	} else if (value == 3) {
		return 100;
	} else if (value == 4) {
		return 1000;
	} else if (value == 5) {
		return 10000;
	} else if (value == 6) {
		return 100000;
	} else if (value == 7) {
		return 1000000;
	} else if (value == 8) {
		return 10000000;
	} else if (value == 9) {
		return 100000000;
	} else if (value == 10) {
		return 1000000000;
	} else if (value == 11) {
		return 10000000000;
	} else if (value == 12) {
		return 100000000000;
	} else if (value == 13) {
		return 1000000000000;
	} else if (value == 14) {
		return 10000000000000;
	} else if (value == 15) {
		return 100000000000000;
	} else if (value == 16) {
		return 1000000000000000;
	} else if (value == 17) {
		return 10000000000000000;
	} else if (value == 18) {
		return 100000000000000000;
	}
	return 1000000000000000000;
}

inline dt mod(dt a, dt b) {
    return a - (b * (a / b));
}

inline dt getDigit(dt value, dt index) {
	return mod(value / getDiv(getDigits(value) - index), 10);
}

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	dt amount;
	cin >> amount;
	dt *a = new dt[amount];
	dt cur;
	dt digits;

	for (dt i = 0; i < amount; i++) {
		cin >> a[i];
	}

	for (dt i = 0; i < amount; i++) {
		cur = a[i];
		dt index = 1;
		dt size = 0;
		digits = 0;

		for (; size < cur; index++) {
			digits = getDigits(index);
			size += digits;
		}

		cout << getDigit(index - 1, cur - (size + 1 - digits)) << '\n';
	}
	//while (1);
	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:

input
1000
672274832941907421
260504693279721732
646999966092970935
100853063389774434
...

correct output
7
2
2
0
9
...

user output
(empty)