CSES - Datatähti 2018 peili - Results
Submission details
Task:Kyselyt
Sender:johku90
Submission time:2017-10-06 14:44:58 +0300
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.06 s1details
#20.08 s2details
#30.20 s3details

Code

#include <iostream>
#include <sstream>
#include <string.h>
#include <math.h>

#define EXP17 100000000000000000
#define EXP16 10000000000000000
#define EXP15 1000000000000000
#define EXP14 100000000000000
#define EXP13 10000000000000
#define EXP12 1000000000000
#define EXP11 100000000000
#define EXP10 10000000000
#define EXP09 1000000000
#define EXP08 100000000
#define EXP07 10000000
#define EXP06 1000000
#define EXP05 100000
#define EXP04 10000
#define EXP03 1000
#define EXP02 100
#define EXP01 10
#define EXP00 1

using namespace std;

//12345678910111213141516171819202122232425

int getDigits(long long n){
	int digits = 0;
	while(n){
		n /= 10;
		digits++;
	}
	return digits;
}

long long getIndex(long long n){
	int digits = getDigits(n);
	long long index = (digits * n);
	for(int d = digits - 1; d > 0; d--){
		index -= pow(10,d);
	}
	return index;
}

string getNumber(long long k){
	long long steps[] = {EXP17,EXP16,EXP15,EXP14,EXP13,EXP12,EXP11,EXP10,EXP09,EXP08,EXP07,EXP06,EXP05,EXP04,EXP03,EXP02,EXP01,EXP00};
	long long number = 0;
	long long numberIndex = 0;
	for(int e=0; e<18; e++){
		while(true){
			long long newIndex = getIndex(number + steps[e]);
			if(newIndex > k) break;
			number += steps[e];
			numberIndex = newIndex;
		}
	}
	cout<<"currentNumber: "<<number<<", numberIndex: "<<numberIndex<<", askedIndex: "<<k<<endl;
	stringstream ss;
	ss<<number;
	string s = ss.str();
	
	return s.substr((int)(k - numberIndex), 1);
}

int main(){
	unsigned int num;
    cin >> num;
    
	long long* kArray = new long long[num];
	
	for(unsigned int n=0; n<num; n++){
		long long k;
		cin >> k;
		kArray[n] = k;
	}
	for(unsigned int n=0; n<num; n++){
		cout<<getNumber(kArray[n])<<endl;
	}
	
	delete [] kArray;
	
	return 0;
}

Test details

Test 1

Group: 1

Verdict:

input
1000
582
214
723
273
...

correct output
0
1
7
7
6
...

user output
currentNumber: 230, numberInde...
Truncated

Test 2

Group: 2

Verdict:

input
1000
615664
916441
627600
279508
...

correct output
1
2
3
2
2
...

user output
currentNumber: 121129, numberI...
Truncated

Test 3

Group: 3

Verdict:

input
1000
672274832941907421
260504693279721732
646999966092970935
100853063389774434
...

correct output
7
2
2
0
9
...

user output
currentNumber: 401991731795893...
Truncated

Error:
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string...