CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:luxask
Submission time:2017-10-06 19:39:20 +0300
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.04 s1details
#20.06 s2details
#3--3details

Code

#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

vector<int> getIndexes() {
	int count, num;
    vector<int> indexes;
    cin >> count;

    for (int i = 0; i < count; ++i)
    {
    	cin >> num;
    	indexes.push_back(num);
    }
    return indexes;
}

int f(int x) {
	return 9 * x * pow(10, x-1);
}

int getFirstNumber(int index, int numCount) {
	return floor(index / (numCount * 10)) + 1;
}

int getMiddleNumber(int index, int numCount, int subNumber) {
	return floor(floor(index / numCount) / pow(10, numCount - subNumber));
}

int getLastNumber(int index, int numCount) {
	return (index / numCount) - 1;
}

int getNumberFromIndex(int index) {
	if (index <= 9)
		return index;

	int numCount = 1;
	while (index >= f(numCount)) {
		index -= f(numCount);
		numCount++;
	}
	switch (int subNumber = index % numCount){
		case 0:
			return getLastNumber(index, numCount);
			break;
		case 1:
			return getFirstNumber(index, numCount);
			break;
		default:
			return getMiddleNumber(index, numCount, subNumber);
			break;
	}
}

int main() {
    auto indexes = getIndexes();
    for (unsigned i=0; i<indexes.size(); i++)
    	cout << getNumberFromIndex(indexes.at(i)) << '\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
130
1
177
27
96
...
Truncated

Test 2

Group: 2

Verdict:

input
1000
615664
916441
627600
279508
...

correct output
1
2
3
2
2
...

user output
2113
712
23
4812
1755
...
Truncated

Test 3

Group: 3

Verdict:

input
1000
672274832941907421
260504693279721732
646999966092970935
100853063389774434
...

correct output
7
2
2
0
9
...

user output
(empty)