Submission #4281452


Source Code Expand

Copy
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.Reader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyInput in = new MyInput(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CMonstersBattleRoyale solver = new CMonstersBattleRoyale();
        solver.solve(1, in, out);
        out.close();
    }

    static class CMonstersBattleRoyale {
        public void solve(int testNumber, MyInput in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.nextIntArray(n);
            long g = 0;
            for (int x : a) g = gcd(x, g);
            out.println(g);
        }

        static long gcd(long n, long r) {
            return r == 0 ? n : gcd(r, n % r);
        }

    }

    static class MyInput {
        private final BufferedReader in;
        private static int pos;
        private static int readLen;
        private static final char[] buffer = new char[1024 * 8];
        private static char[] str = new char[500 * 8 * 2];
        private static boolean[] isDigit = new boolean[256];
        private static boolean[] isSpace = new boolean[256];
        private static boolean[] isLineSep = new boolean[256];

        static {
            for (int i = 0; i < 10; i++) {
                isDigit['0' + i] = true;
            }
            isDigit['-'] = true;
            isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true;
            isLineSep['\r'] = isLineSep['\n'] = true;
        }

        public MyInput(InputStream is) {
            in = new BufferedReader(new InputStreamReader(is));
        }

        public int read() {
            if (pos >= readLen) {
                pos = 0;
                try {
                    readLen = in.read(buffer);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (readLen <= 0) {
                    throw new MyInput.EndOfFileRuntimeException();
                }
            }
            return buffer[pos++];
        }

        public int nextInt() {
            int len = 0;
            str[len++] = nextChar();
            len = reads(len, isSpace);
            int i = 0;
            int ret = 0;
            if (str[0] == '-') {
                i = 1;
            }
            for (; i < len; i++) ret = ret * 10 + str[i] - '0';
            if (str[0] == '-') {
                ret = -ret;
            }
            return ret;
        }

        public char nextChar() {
            while (true) {
                final int c = read();
                if (!isSpace[c]) {
                    return (char) c;
                }
            }
        }

        int reads(int len, boolean[] accept) {
            try {
                while (true) {
                    final int c = read();
                    if (accept[c]) {
                        break;
                    }
                    if (str.length == len) {
                        char[] rep = new char[str.length * 3 / 2];
                        System.arraycopy(str, 0, rep, 0, str.length);
                        str = rep;
                    }
                    str[len++] = (char) c;
                }
            } catch (MyInput.EndOfFileRuntimeException e) {
            }
            return len;
        }

        public int[] nextIntArray(final int n) {
            final int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        static class EndOfFileRuntimeException extends RuntimeException {
        }

    }
}

Submission Info

Submission Time
Task C - Monsters Battle Royale
User tanzaku
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 4149 Byte
Status AC
Exec Time 122 ms
Memory 25172 KB

Judge Result

Set Name All Sample
Score / Max Score 300 / 300 0 / 0
Status
AC × 21
AC × 3
Set Name Test Cases
All 0_random_1, 0_random_2, 0_random_3, 0_random_4, 1_normal_1, 1_normal_2, 1_normal_3, 1_normal_4, 1_normal_5, 1_normal_6, 2_corner_1, 2_corner_2, 2_corner_3, 2_corner_4, 2_corner_5, 2_corner_6, 2_corner_7, 2_corner_8, sample_01, sample_02, sample_03
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
0_random_1 AC 109 ms 20308 KB
0_random_2 AC 118 ms 22612 KB
0_random_3 AC 73 ms 21076 KB
0_random_4 AC 73 ms 21328 KB
1_normal_1 AC 97 ms 20436 KB
1_normal_2 AC 108 ms 21972 KB
1_normal_3 AC 121 ms 21716 KB
1_normal_4 AC 120 ms 22472 KB
1_normal_5 AC 71 ms 20820 KB
1_normal_6 AC 70 ms 18644 KB
2_corner_1 AC 116 ms 24404 KB
2_corner_2 AC 122 ms 22228 KB
2_corner_3 AC 69 ms 21460 KB
2_corner_4 AC 120 ms 23252 KB
2_corner_5 AC 116 ms 21192 KB
2_corner_6 AC 94 ms 25172 KB
2_corner_7 AC 108 ms 20564 KB
2_corner_8 AC 108 ms 22228 KB
sample_01 AC 72 ms 18388 KB
sample_02 AC 71 ms 20564 KB
sample_03 AC 73 ms 20692 KB