結果
問題 | No.1505 Zero-Product Ranges |
ユーザー |
![]() |
提出日時 | 2021-05-14 22:21:40 |
言語 | Java17 (openjdk 17.0.1) |
結果 |
AC
|
実行時間 | 210 ms / 2,000 ms |
コード長 | 3,715 bytes |
コンパイル時間 | 1,917 ms |
使用メモリ | 44,576 KB |
最終ジャッジ日時 | 2022-11-25 19:10:19 |
合計ジャッジ時間 | 11,170 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
34,268 KB |
testcase_01 | AC | 42 ms
34,080 KB |
testcase_02 | AC | 42 ms
34,320 KB |
testcase_03 | AC | 182 ms
41,860 KB |
testcase_04 | AC | 210 ms
44,576 KB |
testcase_05 | AC | 153 ms
40,924 KB |
testcase_06 | AC | 144 ms
41,240 KB |
testcase_07 | AC | 130 ms
40,548 KB |
testcase_08 | AC | 140 ms
40,696 KB |
testcase_09 | AC | 121 ms
39,416 KB |
testcase_10 | AC | 151 ms
41,120 KB |
testcase_11 | AC | 176 ms
43,416 KB |
testcase_12 | AC | 148 ms
41,056 KB |
testcase_13 | AC | 170 ms
41,720 KB |
testcase_14 | AC | 153 ms
42,000 KB |
testcase_15 | AC | 192 ms
44,536 KB |
testcase_16 | AC | 175 ms
42,920 KB |
testcase_17 | AC | 173 ms
42,812 KB |
testcase_18 | AC | 191 ms
42,292 KB |
testcase_19 | AC | 45 ms
34,348 KB |
testcase_20 | AC | 44 ms
34,160 KB |
testcase_21 | AC | 45 ms
34,300 KB |
testcase_22 | AC | 184 ms
42,108 KB |
testcase_23 | AC | 189 ms
42,204 KB |
testcase_24 | AC | 201 ms
41,520 KB |
testcase_25 | AC | 186 ms
42,060 KB |
testcase_26 | AC | 177 ms
42,592 KB |
testcase_27 | AC | 179 ms
42,284 KB |
testcase_28 | AC | 190 ms
42,172 KB |
testcase_29 | AC | 194 ms
42,088 KB |
testcase_30 | AC | 186 ms
42,884 KB |
testcase_31 | AC | 203 ms
42,340 KB |
testcase_32 | AC | 166 ms
42,248 KB |
testcase_33 | AC | 162 ms
41,424 KB |
testcase_34 | AC | 171 ms
42,668 KB |
testcase_35 | AC | 161 ms
41,180 KB |
testcase_36 | AC | 159 ms
41,028 KB |
testcase_37 | AC | 174 ms
42,728 KB |
testcase_38 | AC | 164 ms
40,612 KB |
testcase_39 | AC | 136 ms
40,160 KB |
testcase_40 | AC | 180 ms
41,592 KB |
testcase_41 | AC | 177 ms
41,284 KB |
testcase_42 | AC | 89 ms
35,884 KB |
testcase_43 | AC | 110 ms
37,984 KB |
testcase_44 | AC | 89 ms
36,304 KB |
testcase_45 | AC | 109 ms
36,816 KB |
testcase_46 | AC | 75 ms
36,032 KB |
testcase_47 | AC | 129 ms
38,388 KB |
testcase_48 | AC | 86 ms
35,876 KB |
testcase_49 | AC | 74 ms
35,216 KB |
testcase_50 | AC | 87 ms
36,072 KB |
testcase_51 | AC | 93 ms
36,380 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { static FastScanner sc = new FastScanner(System.in); static PrintWriter pw = new PrintWriter(System.out); static StringBuilder sb = new StringBuilder(); static long mod = (long) 1e9 + 7; public static void main(String[] args) throws Exception { solve(); pw.flush(); } public static void solve() { int n = sc.nextInt(); int[] a = sc.nextIntArray(n); ArrayList<Integer> arr = new ArrayList<>(); for(int i = 0; i < n; i++){ if(a[i] == 0){ arr.add(i); } } arr.add(n); long ans = 0; for(int i = 0; i < arr.size()-1; i++){ long now = arr.get(i)+1; long next = arr.get(i+1)+1; ans += now*(next-now); //pw.println(ans); } pw.println(ans); } static class GeekInteger { public static void save_sort(int[] array) { shuffle(array); Arrays.sort(array); } public static int[] shuffle(int[] array) { int n = array.length; Random random = new Random(); for (int i = 0, j; i < n; i++) { j = i + random.nextInt(n - i); int randomElement = array[j]; array[j] = array[i]; array[i] = randomElement; } return array; } public static void save_sort(long[] array) { shuffle(array); Arrays.sort(array); } public static long[] shuffle(long[] array) { int n = array.length; Random random = new Random(); for (int i = 0, j; i < n; i++) { j = i + random.nextInt(n - i); long randomElement = array[j]; array[j] = array[i]; array[i] = randomElement; } return array; } } } class FastScanner { private BufferedReader reader = null; private StringTokenizer tokenizer = null; public FastScanner(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } public FastScanner(FileReader in) { reader = new BufferedReader(in); tokenizer = null; } public String next() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String[] nextArray(int n) { String[] a = new String[n]; for (int i = 0; i < n; i++) a[i] = next(); 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 long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } }