CSES - Datatähti Open 2021 - Results
Submission details
Task:Greater Integers
Sender:jjlowercase
Submission time:2021-01-30 02:44:00 +0200
Language:Java
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#10.14 s1, 2details
#20.16 s2details

Code

import java.io.*;
import java.util.*;

public class A {
    static class Reader {
        final private int BUFFER_SIZE = 1 << 25;
        private DataInputStream din; 
        private byte[] buffer; 
        private int bufferPointer, bytesRead; 
  
        public Reader() 
        { 
            din = new DataInputStream(System.in); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
  
        public Reader(String file_name) throws IOException 
        { 
            din = new DataInputStream(new FileInputStream(file_name)); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
  
        public String next() throws IOException 
        { 
            byte[] buf = new byte[64]; // line length 
            int cnt = 0, c; 
            while ((c = read()) != -1) 
            { 
                if (c == '\n') 
                    break; 
                buf[cnt++] = (byte) c; 
            } 
            return new String(buf, 0, cnt); 
        } 
  
        public int nint() throws IOException 
        { 
            int ret = 0; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
            do
            { 
                ret = ret * 10 + c - '0'; 
            }  while ((c = read()) >= '0' && c <= '9'); 
  
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        public long nlong() throws IOException 
        { 
            long ret = 0; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
            do { 
                ret = ret * 10 + c - '0'; 
            } 
            while ((c = read()) >= '0' && c <= '9'); 
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        public double ndouble() throws IOException 
        { 
            double ret = 0, div = 1; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
  
            do { 
                ret = ret * 10 + c - '0'; 
            } 
            while ((c = read()) >= '0' && c <= '9'); 
  
            if (c == '.') 
            { 
                while ((c = read()) >= '0' && c <= '9') 
                { 
                    ret += (c - '0') / (div *= 10); 
                } 
            } 
  
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        private void fillBuffer() throws IOException 
        { 
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 
            if (bytesRead == -1) 
                buffer[0] = -1; 
        } 
  
        private byte read() throws IOException 
        { 
            if (bufferPointer == bytesRead) 
                fillBuffer(); 
            return buffer[bufferPointer++]; 
        } 
  
        public void close() throws IOException 
        { 
            if (din == null) 
                return; 
            din.close(); 
        } 
    }  
    static Reader in = new Reader();
    static PrintWriter pw = new PrintWriter(System.out);
    public static void main(String[] args) throws IOException {
        int t = in.nint();
        while (t --> 0) {
            String s = in.next();
            //pw.println("s: " + s);
            long sc = Long.parseLong(s);
            if (sc < 9) {
                pw.println(sc+1);
                continue;
            }
            if (s.charAt(0) == '9') {
                boolean notfull = false;
                for (int i=0;i<s.length();++i) {
                    if (s.charAt(i) != '9') {
                        notfull = true;
                        break;
                    }
                }
                if (notfull) {
                    for (int i=0;i<s.length();++i) pw.print('9');
                    pw.println();
                    continue;
                } else {
                    for (int i=0;i<s.length()+1;++i) pw.print('1');
                    pw.println();
                    continue;
                }
            }
            boolean next = false;
            for (int i=1;i<s.length();++i) {
                if (s.charAt(i) > s.charAt(0)) {
                    next = true;
                }
            }
            if (next) {
                //pw.println("next");
                char c = (char)(s.charAt(0) + 1);
                for (int i=0;i<s.length();++i) pw.print(c);
                pw.println();
            } else {
                //pw.println("not next");
                for (int i=0;i<s.length();++i) pw.print(s.charAt(0));
                pw.println();
            }
        }
        pw.close();
    }
}

Test details

Test 1

Group: 1, 2

Verdict:

input
1000
1
2
3
4
...

correct output
2
3
4
5
6
...

user output
2
3
4
5
6
...
Truncated

Test 2

Group: 2

Verdict:

input
1000
735425311146082632
756615631808964686
466489470801941584
100417544394053220
...

correct output
777777777777777777
777777777777777777
555555555555555555
111111111111111111
555555555555555555
...

user output
888888888888888888
888888888888888888
555555555555555555
222222222222222222
55555555555555
...
Truncated