Submission #2499901


Source Code Expand

Copy
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
    String s;
    int k;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        s = sc.next();
        k = sc.nextInt();
        solve();
    }

    void solve() {
        PriorityQueue<String> pQueue = new PriorityQueue<>();
        SortedSet<String> set = new TreeSet<>();
        char[] cs = s.toCharArray();
        SortedSet<Character> setC = new TreeSet<>();
        for (int i = 0; i < cs.length; i++) {
            setC.add(cs[i]);
        }
        for (char c : setC) {
            for (int i = 0; i < s.length(); i++) {
                if (cs[i] != c) {
                    continue;
                }
                for (int j = 1; j <= k; j++) {
                    if (i + j <= s.length()) {
                        set.add(s.substring(i, i + j));
                    }
                }
            }
            if (set.size() >= k) {
                break;
            }
        }
        int count = 1;
        for (String str : set) {
            if (count == k) {
                System.out.println(str);
                break;
            }
            count++;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Submission Info

Submission Time
Task C - K-th Substring
User ynish
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 2690 Byte
Status AC
Exec Time 101 ms
Memory 25044 KB

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 200 / 200 100 / 100
Status
AC × 3
AC × 11
AC × 19
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt
Subtask 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 2_011.txt, 2_012.txt, 2_013.txt, 2_014.txt, 2_015.txt, 2_016.txt, 2_017.txt, 2_018.txt
Case Name Status Exec Time Memory
0_000.txt AC 84 ms 20052 KB
0_001.txt AC 75 ms 21332 KB
0_002.txt AC 74 ms 18260 KB
1_003.txt AC 74 ms 20692 KB
1_004.txt AC 73 ms 18772 KB
1_005.txt AC 85 ms 17748 KB
1_006.txt AC 73 ms 25044 KB
1_007.txt AC 72 ms 18388 KB
1_008.txt AC 72 ms 19284 KB
1_009.txt AC 72 ms 18772 KB
1_010.txt AC 72 ms 19156 KB
2_011.txt AC 101 ms 21844 KB
2_012.txt AC 101 ms 22612 KB
2_013.txt AC 87 ms 19540 KB
2_014.txt AC 101 ms 21504 KB
2_015.txt AC 90 ms 20436 KB
2_016.txt AC 96 ms 19412 KB
2_017.txt AC 98 ms 20820 KB
2_018.txt AC 99 ms 22884 KB