結果
問題 | No.1505 Zero-Product Ranges |
ユーザー | shojin_pro |
提出日時 | 2021-05-14 22:21:40 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 233 ms / 2,000 ms |
コード長 | 3,715 bytes |
コンパイル時間 | 2,707 ms |
コンパイル使用メモリ | 79,860 KB |
実行使用メモリ | 48,448 KB |
最終ジャッジ日時 | 2024-10-02 01:55:00 |
合計ジャッジ時間 | 12,622 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
36,992 KB |
testcase_01 | AC | 55 ms
37,164 KB |
testcase_02 | AC | 53 ms
36,984 KB |
testcase_03 | AC | 186 ms
45,692 KB |
testcase_04 | AC | 233 ms
48,044 KB |
testcase_05 | AC | 171 ms
44,820 KB |
testcase_06 | AC | 157 ms
44,740 KB |
testcase_07 | AC | 138 ms
42,040 KB |
testcase_08 | AC | 148 ms
44,764 KB |
testcase_09 | AC | 143 ms
43,264 KB |
testcase_10 | AC | 156 ms
43,696 KB |
testcase_11 | AC | 179 ms
44,912 KB |
testcase_12 | AC | 144 ms
43,520 KB |
testcase_13 | AC | 201 ms
45,812 KB |
testcase_14 | AC | 186 ms
45,136 KB |
testcase_15 | AC | 227 ms
48,448 KB |
testcase_16 | AC | 231 ms
46,092 KB |
testcase_17 | AC | 232 ms
45,580 KB |
testcase_18 | AC | 233 ms
45,844 KB |
testcase_19 | AC | 53 ms
36,872 KB |
testcase_20 | AC | 53 ms
37,168 KB |
testcase_21 | AC | 54 ms
37,112 KB |
testcase_22 | AC | 211 ms
45,668 KB |
testcase_23 | AC | 212 ms
46,256 KB |
testcase_24 | AC | 188 ms
45,660 KB |
testcase_25 | AC | 217 ms
45,340 KB |
testcase_26 | AC | 203 ms
45,932 KB |
testcase_27 | AC | 229 ms
45,580 KB |
testcase_28 | AC | 228 ms
45,548 KB |
testcase_29 | AC | 231 ms
46,176 KB |
testcase_30 | AC | 204 ms
46,152 KB |
testcase_31 | AC | 211 ms
46,076 KB |
testcase_32 | AC | 165 ms
46,212 KB |
testcase_33 | AC | 168 ms
44,964 KB |
testcase_34 | AC | 181 ms
45,452 KB |
testcase_35 | AC | 162 ms
43,584 KB |
testcase_36 | AC | 173 ms
44,840 KB |
testcase_37 | AC | 189 ms
46,164 KB |
testcase_38 | AC | 169 ms
43,500 KB |
testcase_39 | AC | 186 ms
44,976 KB |
testcase_40 | AC | 193 ms
46,028 KB |
testcase_41 | AC | 180 ms
45,496 KB |
testcase_42 | AC | 109 ms
39,392 KB |
testcase_43 | AC | 113 ms
39,808 KB |
testcase_44 | AC | 106 ms
39,752 KB |
testcase_45 | AC | 110 ms
40,108 KB |
testcase_46 | AC | 104 ms
39,352 KB |
testcase_47 | AC | 105 ms
40,200 KB |
testcase_48 | AC | 110 ms
39,508 KB |
testcase_49 | AC | 94 ms
38,892 KB |
testcase_50 | AC | 104 ms
39,424 KB |
testcase_51 | AC | 110 ms
39,752 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; } }