結果

問題 No.1505 Zero-Product Ranges
ユーザー shojin_proshojin_pro
提出日時 2021-05-14 22:21:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 3,715 bytes
コンパイル時間 2,436 ms
コンパイル使用メモリ 80,136 KB
実行使用メモリ 58,576 KB
最終ジャッジ日時 2024-04-10 00:49:57
合計ジャッジ時間 12,184 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
50,200 KB
testcase_01 AC 51 ms
50,432 KB
testcase_02 AC 51 ms
50,504 KB
testcase_03 AC 210 ms
56,244 KB
testcase_04 AC 237 ms
58,576 KB
testcase_05 AC 140 ms
54,940 KB
testcase_06 AC 147 ms
55,148 KB
testcase_07 AC 131 ms
54,260 KB
testcase_08 AC 141 ms
55,244 KB
testcase_09 AC 147 ms
55,352 KB
testcase_10 AC 149 ms
55,376 KB
testcase_11 AC 172 ms
56,472 KB
testcase_12 AC 134 ms
54,780 KB
testcase_13 AC 196 ms
56,408 KB
testcase_14 AC 173 ms
56,128 KB
testcase_15 AC 236 ms
58,424 KB
testcase_16 AC 232 ms
56,236 KB
testcase_17 AC 201 ms
56,408 KB
testcase_18 AC 238 ms
56,312 KB
testcase_19 AC 53 ms
50,140 KB
testcase_20 AC 53 ms
50,240 KB
testcase_21 AC 54 ms
50,132 KB
testcase_22 AC 228 ms
56,208 KB
testcase_23 AC 232 ms
56,520 KB
testcase_24 AC 233 ms
56,320 KB
testcase_25 AC 208 ms
56,188 KB
testcase_26 AC 222 ms
56,468 KB
testcase_27 AC 225 ms
56,352 KB
testcase_28 AC 192 ms
56,220 KB
testcase_29 AC 218 ms
56,184 KB
testcase_30 AC 226 ms
56,440 KB
testcase_31 AC 219 ms
56,348 KB
testcase_32 AC 177 ms
56,624 KB
testcase_33 AC 165 ms
55,112 KB
testcase_34 AC 188 ms
56,492 KB
testcase_35 AC 156 ms
55,200 KB
testcase_36 AC 156 ms
55,648 KB
testcase_37 AC 163 ms
55,692 KB
testcase_38 AC 161 ms
55,204 KB
testcase_39 AC 173 ms
55,372 KB
testcase_40 AC 170 ms
55,900 KB
testcase_41 AC 179 ms
56,528 KB
testcase_42 AC 103 ms
51,964 KB
testcase_43 AC 106 ms
51,936 KB
testcase_44 AC 98 ms
52,136 KB
testcase_45 AC 107 ms
51,912 KB
testcase_46 AC 95 ms
51,984 KB
testcase_47 AC 110 ms
51,960 KB
testcase_48 AC 105 ms
52,060 KB
testcase_49 AC 91 ms
51,684 KB
testcase_50 AC 104 ms
52,120 KB
testcase_51 AC 106 ms
51,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
    }
}
0