結果
問題 | No.1470 Mex Sum |
ユーザー | neko_the_shadow |
提出日時 | 2021-04-13 10:28:22 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 343 ms / 2,000 ms |
コード長 | 5,133 bytes |
コンパイル時間 | 2,329 ms |
コンパイル使用メモリ | 92,268 KB |
実行使用メモリ | 70,524 KB |
最終ジャッジ日時 | 2023-09-11 14:57:26 |
合計ジャッジ時間 | 18,320 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
50,684 KB |
testcase_01 | AC | 59 ms
50,676 KB |
testcase_02 | AC | 134 ms
56,900 KB |
testcase_03 | AC | 128 ms
56,956 KB |
testcase_04 | AC | 131 ms
57,028 KB |
testcase_05 | AC | 128 ms
56,824 KB |
testcase_06 | AC | 127 ms
57,044 KB |
testcase_07 | AC | 128 ms
56,724 KB |
testcase_08 | AC | 128 ms
57,068 KB |
testcase_09 | AC | 131 ms
56,712 KB |
testcase_10 | AC | 118 ms
57,020 KB |
testcase_11 | AC | 129 ms
55,388 KB |
testcase_12 | AC | 333 ms
68,700 KB |
testcase_13 | AC | 325 ms
68,048 KB |
testcase_14 | AC | 316 ms
68,144 KB |
testcase_15 | AC | 328 ms
68,700 KB |
testcase_16 | AC | 321 ms
68,204 KB |
testcase_17 | AC | 343 ms
68,904 KB |
testcase_18 | AC | 324 ms
68,464 KB |
testcase_19 | AC | 321 ms
68,744 KB |
testcase_20 | AC | 323 ms
68,572 KB |
testcase_21 | AC | 334 ms
68,128 KB |
testcase_22 | AC | 332 ms
69,108 KB |
testcase_23 | AC | 333 ms
68,780 KB |
testcase_24 | AC | 332 ms
68,376 KB |
testcase_25 | AC | 330 ms
68,488 KB |
testcase_26 | AC | 330 ms
68,260 KB |
testcase_27 | AC | 323 ms
68,760 KB |
testcase_28 | AC | 328 ms
68,896 KB |
testcase_29 | AC | 327 ms
68,608 KB |
testcase_30 | AC | 325 ms
68,584 KB |
testcase_31 | AC | 313 ms
68,780 KB |
testcase_32 | AC | 327 ms
68,932 KB |
testcase_33 | AC | 324 ms
68,152 KB |
testcase_34 | AC | 330 ms
68,272 KB |
testcase_35 | AC | 327 ms
68,640 KB |
testcase_36 | AC | 322 ms
68,360 KB |
testcase_37 | AC | 301 ms
69,652 KB |
testcase_38 | AC | 309 ms
69,820 KB |
testcase_39 | AC | 308 ms
70,524 KB |
testcase_40 | AC | 315 ms
70,020 KB |
testcase_41 | AC | 322 ms
69,556 KB |
testcase_42 | AC | 310 ms
70,276 KB |
testcase_43 | AC | 313 ms
69,572 KB |
testcase_44 | AC | 320 ms
69,772 KB |
testcase_45 | AC | 317 ms
69,884 KB |
testcase_46 | AC | 325 ms
70,228 KB |
testcase_47 | AC | 321 ms
69,864 KB |
testcase_48 | AC | 307 ms
69,528 KB |
testcase_49 | AC | 311 ms
70,012 KB |
testcase_50 | AC | 323 ms
69,744 KB |
ソースコード
package _1470; import java.io.BufferedReader; import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.io.UncheckedIOException; import java.math.BigInteger; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; import java.util.List; import java.util.function.Supplier; import java.util.regex.Pattern; public class Main { public void exec() { int n = stdin.nextInt(); long[] a = stdin.nextLongArray(n); long one = 0; long two = 0; long up2 = 0; long up3 = 0; for (int i = 0; i < n; i++) { if (a[i]==1) one++; if (a[i]==2) two++; if (a[i]>=2) up2++; if (a[i]>=3) up3++; } long ans = 0; for (int i = 0; i < n; i++) { if (a[i]==1) one--; if (a[i]==2) two--; if (a[i]>=2) up2--; if (a[i]>=3) up3--; if (a[i]==1) { ans += 2*(one+up3) + 3*two; } else if (a[i]==2) { ans += 1*up2 + 3*one; } else { ans += 1*up2 + 2*one; } } stdout.println(ans); } private static final Stdin stdin = new Stdin(System.in); private static final Stdout stdout = new Stdout(System.out); public static void main(String[] args) { try { new Main().exec(); } finally { stdout.flush(); } } public static class Stdin { private Deque<String> queue; private BufferedReader in; private Pattern space; public Stdin(InputStream in) { this.queue = new ArrayDeque<>(); this.in = new BufferedReader(new InputStreamReader(in)); this.space = Pattern.compile(" "); } public String nextString() { if (queue.isEmpty()) { try { String line = in.readLine(); if (line == null) { throw new EOFException(); } space.splitAsStream(line).forEach(this.queue::addLast); } catch (IOException e) { throw new UncheckedIOException(e); } } return queue.removeFirst(); } public int nextInt() { return Integer.parseInt(nextString()); } public double nextDouble() { return Double.parseDouble(nextString()); } public long nextLong() { return Long.parseLong(nextString()); } public BigInteger nextBigInteger() { return new BigInteger(nextString()); } public String[] nextStringArray(int n) { String[] a = new String[n]; for (int i = 0; i < n; i++) a[i] = nextString(); return a; } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public double[] nextDoubleArray(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextDouble(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public BigInteger[] nexBigIntegerArray(int n) { BigInteger[] a = new BigInteger[n]; for (int i = 0; i < n; i++) a[i] = nextBigInteger(); return a; } public List<Integer> nextIntegerList(int n) { return nextList(n, this::nextInt); } public List<Long> nextLongList(int n) { return nextList(n, this::nextLong); } public List<Double> nextDoubleList(int n) { return nextList(n, this::nextDouble); } public List<String> nextStringList(int n) { return nextList(n, this::nextString); } public List<BigInteger> nextBigIntegerList(int n) { return nextList(n, this::nextBigInteger); } private <T> List<T> nextList(int n, Supplier<T> supplier) { List<T> a = new ArrayList<>(); for (int i = 0; i < n; i++) a.add(supplier.get()); return a; } } public static class Stdout { private PrintWriter stdout; public Stdout(PrintStream stdout) { this.stdout = new PrintWriter(stdout, false); } public void println(Object ... objs) { for (int i = 0, len = objs.length; i < len; i++) { stdout.print(objs[i]); if (i != len-1) stdout.print(' '); } stdout.println(); } public void flush() { stdout.flush(); } } }