Submission #1669086


Source Code Expand

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

public class Main {
    private FastScanner in;
    private PrintWriter out;

    int cnt = 0;

    class T implements Comparable<T> {
        String s;
        int id = cnt++;

        public T(String s) {
            this.s = s;
        }

        @Override
        public int compareTo(T o) {
            int c = s.compareTo(o.s);
            if (c != 0) {
                return c;
            }
            return Integer.compare(id, o.id);
        }
    }

    String getMin(String s) {
        String res = s;
        for (int i = 1; i < s.length(); i++) {
            String t = s.substring(i) + s.substring(0, i);
            if (t.compareTo(res) < 0) {
                res = t;
            }
        }
        return res;
    }

    void check(String s) {
        ArrayList<Character> a = new ArrayList<>();
        for (char c : s.toCharArray()) {
            a.add(c);
        }
        char[] tmp = new char[s.length()];
        for (int it = 0; it < 1231; it++) {
            Collections.shuffle(a);
            int z = 0;
            for (char c : a) {
                tmp[z++] = c;
            }
            String xx = new String(tmp);
            if (getMin(xx).compareTo(s) > 0) {
                throw new AssertionError();
            }
        }
    }

    String solve(int x, int y, int z) {
        if (x + y + z == 0) {
            return "";
        }
        TreeSet<T> ts = new TreeSet<>();
        for (int i = 0; i < x; i++) {
            ts.add(new T("a"));
        }
        for (int i = 0; i < y; i++) {
            ts.add(new T("b"));
        }
        for (int i = 0; i < z; i++) {
            ts.add(new T("c"));
        }
        while (ts.size() > 1) {
            T first = ts.pollFirst();
            T last = ts.pollLast();
            ts.add(new T(first.s + last.s));
        }
        String res = (ts.first().s);
        check(res);
        return res;
    }

    void solve123() {
        final int M = 10;
        for (int x = 0; x < M; x++) {
            for (int y = 0; y < M; y++) {
                for (int z = 0; z < M; z++) {
                    solve(x, y, z);
                    System.err.println(x + " " + y + " "+ z);
                }
            }
        }
    }

    void solve() {
        int x = in.nextInt();
        int y = in.nextInt();
        int z = in.nextInt();
        out.println(solve(x, y, z));
    }

    private void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    private void runIO() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    private class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

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

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

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

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

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

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

Submission Info

Submission Time
Task F - Largest Smallest Cyclic Shift
User qwerty787788
Language Java8 (OpenJDK 1.8.0)
Score 1600
Code Size 4692 Byte
Status
Exec Time 165 ms
Memory 42964 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 example0.txt, example1.txt
All 1600 / 1600 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, 059.txt, 060.txt, 061.txt, 062.txt, 063.txt, 064.txt, 065.txt, 066.txt, 067.txt, 068.txt, 069.txt, 070.txt, 071.txt, 072.txt, 073.txt, 074.txt, 075.txt, 076.txt, 077.txt, 078.txt, 079.txt, 080.txt, 081.txt, 082.txt, 083.txt, 084.txt, 085.txt, 086.txt, 087.txt, 088.txt, 089.txt, 090.txt, 091.txt, 092.txt, 093.txt, 094.txt, 095.txt, 096.txt, 097.txt, 098.txt, 099.txt, 100.txt, 101.txt, 102.txt, 103.txt, 104.txt, 105.txt, 106.txt, 107.txt, 108.txt, 109.txt, 110.txt, 111.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt 84 ms 18644 KB
001.txt 85 ms 19412 KB
002.txt 93 ms 19788 KB
003.txt 83 ms 18516 KB
004.txt 87 ms 23504 KB
005.txt 95 ms 22092 KB
006.txt 98 ms 20048 KB
007.txt 102 ms 20948 KB
008.txt 101 ms 20820 KB
009.txt 102 ms 24276 KB
010.txt 98 ms 23636 KB
011.txt 103 ms 23636 KB
012.txt 100 ms 24788 KB
013.txt 93 ms 22996 KB
014.txt 107 ms 23764 KB
015.txt 109 ms 21460 KB
016.txt 102 ms 25684 KB
017.txt 99 ms 29780 KB
018.txt 109 ms 26324 KB
019.txt 112 ms 29908 KB
020.txt 110 ms 29652 KB
021.txt 114 ms 30292 KB
022.txt 112 ms 30164 KB
023.txt 112 ms 29012 KB
024.txt 116 ms 32212 KB
025.txt 113 ms 31956 KB
026.txt 109 ms 31952 KB
027.txt 120 ms 31316 KB
028.txt 118 ms 34132 KB
029.txt 123 ms 35156 KB
030.txt 126 ms 36180 KB
031.txt 125 ms 36180 KB
032.txt 125 ms 36180 KB
033.txt 132 ms 38100 KB
034.txt 125 ms 35156 KB
035.txt 128 ms 38100 KB
036.txt 131 ms 31956 KB
037.txt 119 ms 38100 KB
038.txt 130 ms 33108 KB
039.txt 132 ms 36436 KB
040.txt 133 ms 38228 KB
041.txt 120 ms 38100 KB
042.txt 130 ms 34772 KB
043.txt 135 ms 36052 KB
044.txt 134 ms 42324 KB
045.txt 139 ms 40148 KB
046.txt 140 ms 40404 KB
047.txt 138 ms 40148 KB
048.txt 136 ms 37332 KB
049.txt 138 ms 40532 KB
050.txt 142 ms 38996 KB
051.txt 139 ms 37204 KB
052.txt 165 ms 39892 KB
053.txt 139 ms 40656 KB
054.txt 133 ms 39124 KB
055.txt 140 ms 38612 KB
056.txt 132 ms 38996 KB
057.txt 149 ms 40452 KB
058.txt 136 ms 37716 KB
059.txt 137 ms 37076 KB
060.txt 135 ms 42324 KB
061.txt 142 ms 39892 KB
062.txt 138 ms 39508 KB
063.txt 140 ms 37764 KB
064.txt 140 ms 41044 KB
065.txt 142 ms 40532 KB
066.txt 134 ms 39380 KB
067.txt 145 ms 42068 KB
068.txt 141 ms 38996 KB
069.txt 127 ms 39892 KB
070.txt 141 ms 42324 KB
071.txt 138 ms 40788 KB
072.txt 138 ms 39252 KB
073.txt 137 ms 42324 KB
074.txt 142 ms 38612 KB
075.txt 140 ms 40404 KB
076.txt 139 ms 40532 KB
077.txt 147 ms 37844 KB
078.txt 142 ms 36780 KB
079.txt 145 ms 42056 KB
080.txt 139 ms 42324 KB
081.txt 142 ms 42964 KB
082.txt 142 ms 38228 KB
083.txt 145 ms 40420 KB
084.txt 125 ms 42324 KB
085.txt 147 ms 39124 KB
086.txt 144 ms 39112 KB
087.txt 153 ms 38328 KB
088.txt 139 ms 40404 KB
089.txt 138 ms 37632 KB
090.txt 143 ms 38100 KB
091.txt 137 ms 40916 KB
092.txt 143 ms 38996 KB
093.txt 145 ms 40404 KB
094.txt 144 ms 40404 KB
095.txt 141 ms 39636 KB
096.txt 138 ms 40404 KB
097.txt 143 ms 39764 KB
098.txt 143 ms 38868 KB
099.txt 145 ms 37844 KB
100.txt 144 ms 40532 KB
101.txt 140 ms 40916 KB
102.txt 138 ms 42324 KB
103.txt 139 ms 37576 KB
104.txt 138 ms 38228 KB
105.txt 133 ms 40404 KB
106.txt 137 ms 39252 KB
107.txt 138 ms 37460 KB
108.txt 148 ms 38188 KB
109.txt 135 ms 38356 KB
110.txt 137 ms 40276 KB
111.txt 136 ms 40404 KB
example0.txt 101 ms 19668 KB
example1.txt 93 ms 21588 KB