Submission #846825


Source Code Expand

Copy
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long[] s = new long[n];
            for (int i = 0; i < n; ++i) {
                s[i] = in.nextLong();
            }
            long max = 1;
            for (long x : s) max = Math.max(max, x);
            long sq3 = Math.round(Math.pow(max, 1. / 3));
            while (sq3 * sq3 * sq3 <= max) ++sq3;
            long maxsq2 = Math.round(Math.sqrt(max));
            while (maxsq2 * maxsq2 <= max) ++maxsq2;
            boolean[] pr = new boolean[(int) sq3];
            Arrays.fill(pr, 2, pr.length, true);
            int prCount = 0;
            for (int i = 2; i < pr.length; ++i)
                if (pr[i]) {
                    ++prCount;
                    for (int j = i * 2; j < pr.length; j += i) pr[j] = false;
                }
            int[] prs = new int[prCount];
            prCount = 0;
            for (int i = 2; i < pr.length; ++i) if (pr[i]) prs[prCount++] = i;
            int res = 0;
            int cubes = 0;
            long[] vals = new long[s.length];
            int valsCount = 0;
            outer:
            for (long x : s) {
                long c = 1;
                long o = 1;
                for (int p : prs) {
                    int deg = 0;
                    while (x % p == 0) {
                        ++deg;
                        x /= p;
                    }
                    deg %= 3;
                    if (deg == 1) {
                        c *= p;
                        o *= p;
                        if (o > max) {
                            ++res;
                            continue outer;
                        }
                        o *= p;
                        if (o > max) {
                            ++res;
                            continue outer;
                        }
                    } else if (deg == 2) {
                        c *= p * p;
                        o *= p;
                        if (o > max) {
                            ++res;
                            continue outer;
                        }
                    }
                }
                if (x > 1) {
                    long sq2 = Math.round(Math.sqrt(x));
                    if (sq2 * sq2 == x) {
                        c *= sq2 * sq2;
                        o *= sq2;
                        if (o > max) {
                            ++res;
                            continue;
                        }
                    } else if (x >= maxsq2) {
                        ++res;
                        continue;
                    } else {
                        c *= x;
                        o *= x;
                        if (o > max) {
                            ++res;
                            continue;
                        }
                        o *= x;
                        if (o > max) {
                            ++res;
                            continue;
                        }
                    }
                }
                if (c == 1) {
                    ++cubes;
                    continue;
                }
                if (c < o) {
                    vals[valsCount++] = c * 2;
                } else {
                    vals[valsCount++] = o * 2 + 1;
                }
            }
            vals = Arrays.copyOf(vals, valsCount);
            Arrays.sort(vals);
            for (int i = 0; i < vals.length; ) {
                int j = i;
                int same = 0;
                while (j < vals.length && vals[j] == vals[i]) {
                    ++same;
                    ++j;
                }
                int diff = 0;
                while (j < vals.length && vals[j] == (vals[i] ^ 1)) {
                    ++diff;
                    ++j;
                }
                res += Math.max(same, diff);
                i = j;
            }
            res += Math.min(1, cubes);
            out.println(res);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

    }
}

Submission Info

Submission Time
Task D - Anticube
User Petr
Language Java8 (OpenJDK 1.8.0)
Score 1100
Code Size 5807 Byte
Status AC
Exec Time 2642 ms
Memory 20904 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1100 / 1100
Status
AC × 3
AC × 51
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 1155 ms 20520 KB
02.txt AC 1125 ms 20572 KB
03.txt AC 1128 ms 20480 KB
04.txt AC 1136 ms 20520 KB
05.txt AC 1150 ms 20568 KB
06.txt AC 1136 ms 20516 KB
07.txt AC 1162 ms 20472 KB
08.txt AC 1158 ms 20408 KB
09.txt AC 1165 ms 20416 KB
10.txt AC 1158 ms 20584 KB
11.txt AC 859 ms 20500 KB
12.txt AC 891 ms 20556 KB
13.txt AC 1185 ms 20572 KB
14.txt AC 2642 ms 20620 KB
15.txt AC 1665 ms 20496 KB
16.txt AC 1203 ms 20904 KB
17.txt AC 1318 ms 20484 KB
18.txt AC 1276 ms 20364 KB
19.txt AC 1282 ms 20552 KB
20.txt AC 1258 ms 20472 KB
21.txt AC 1238 ms 20708 KB
22.txt AC 1206 ms 20436 KB
23.txt AC 1236 ms 20640 KB
24.txt AC 1249 ms 20296 KB
25.txt AC 1298 ms 20548 KB
26.txt AC 1224 ms 20564 KB
27.txt AC 356 ms 20524 KB
28.txt AC 273 ms 19896 KB
29.txt AC 286 ms 19544 KB
30.txt AC 282 ms 20092 KB
31.txt AC 294 ms 20264 KB
32.txt AC 292 ms 20056 KB
33.txt AC 154 ms 8276 KB
34.txt AC 1283 ms 20304 KB
35.txt AC 788 ms 20408 KB
36.txt AC 154 ms 8144 KB
37.txt AC 1197 ms 20656 KB
38.txt AC 1168 ms 20608 KB
39.txt AC 1195 ms 20564 KB
40.txt AC 1189 ms 20540 KB
41.txt AC 149 ms 8276 KB
42.txt AC 149 ms 8276 KB
43.txt AC 153 ms 8276 KB
44.txt AC 148 ms 8276 KB
45.txt AC 155 ms 8144 KB
46.txt AC 149 ms 8148 KB
47.txt AC 152 ms 8144 KB
48.txt AC 153 ms 8148 KB
s1.txt AC 153 ms 8276 KB
s2.txt AC 149 ms 8276 KB
s3.txt AC 152 ms 8272 KB