CSES - Datatähti 2018 alku - Results
Submission details
Task:Kyselyt
Sender:10GOTO10
Submission time:2017-10-05 17:00:44 +0300
Language:Java
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED12
#2ACCEPTED25
#3ACCEPTED63
Test results
testverdicttimegroup
#1ACCEPTED0.25 s1details
#2ACCEPTED0.28 s2details
#3ACCEPTED0.29 s3details

Code

import java.util.*;
import java.math.BigInteger;

class kyselyt
{
    static long[] in = new long[1002];
    static long[] digitsSum = new long[19];
    static long inputLen;
    static int digitsInNum;
    static long numWithAns;
    static String ans;
    
    public static long divCeiling(long x, long y) {
 long q = x / y;
 if (q * y < x) ++q;
 return q;
    } 
 
    public static long power(long b, long e) {
 long result = 1;
 for (long i = 0; i < e; ++i) {
  result *= b;
 }
 return (result);
    }
    
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner scanner = new Scanner(System.in);
        inputLen = scanner.nextInt();
        digitsSum[0] = 0;
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i<inputLen; i++) {
            in[i] = scanner.nextLong();
            for(int j = 1; j<19; j++) {
                digitsSum[j] = digitsSum[j-1] + (long)(j*9*Math.pow(10, j-1));
                if(in[i]<=digitsSum[j] && in[i]>digitsSum[j-1]) digitsInNum = j;
            }
            numWithAns = divCeiling(in[i]-digitsSum[digitsInNum-1],digitsInNum)+power(10, digitsInNum-1)-1;
            ans = Long.toString(numWithAns);
            System.out.println(Character.getNumericValue(ans.charAt(ans.length()-1-(int)((digitsSum[digitsInNum]-in[i])%digitsInNum))));
        }
    }
}

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