Task: | Kyselyt |
Sender: | johku90 |
Submission time: | 2017-10-06 15:16:45 +0300 |
Language: | C++ |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 12 |
#2 | ACCEPTED | 25 |
#3 | ACCEPTED | 63 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.03 s | 1 | details |
#2 | ACCEPTED | 0.07 s | 2 | details |
#3 | ACCEPTED | 0.06 s | 3 | details |
Code
#include <iostream> #include <sstream> #include <string.h> #include <math.h> #include <cinttypes> #define EXP18 1000000000000000000 #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(uintmax_t n){ int digits = 0; while(n){ n /= 10; digits++; } return digits; } uintmax_t getIndex(uintmax_t n){ int digits = getDigits(n); uintmax_t index = (digits * n); for(int d = digits - 1; d > 0; d--){ uintmax_t power = 1; for(int p = 0; p<d; p++) power *= 10; index -= power; } return index; } string getNumber(uintmax_t k){ uintmax_t steps[] = {EXP18,EXP17,EXP16,EXP15,EXP14,EXP13,EXP12,EXP11,EXP10,EXP09,EXP08,EXP07,EXP06,EXP05,EXP04,EXP03,EXP02,EXP01,EXP00}; uintmax_t number = 0; uintmax_t numberIndex = 0; for(int e=0; e<19; e++){ while(true){ uintmax_t 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((long)(k - numberIndex), 1); } int main(){ unsigned int num; cin >> num; uintmax_t* kArray = new uintmax_t[num]; for(unsigned int n=0; n<num; n++){ uintmax_t 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: 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 |