結果

問題 No.1505 Zero-Product Ranges
ユーザー shojin_proshojin_pro
提出日時 2021-05-14 22:21:40
言語 Java19
(openjdk 21)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 3,715 bytes
コンパイル時間 2,665 ms
コンパイル使用メモリ 76,476 KB
実行使用メモリ 59,072 KB
最終ジャッジ日時 2023-07-25 07:23:09
合計ジャッジ時間 12,880 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,728 KB
testcase_01 AC 45 ms
49,612 KB
testcase_02 AC 45 ms
49,636 KB
testcase_03 AC 187 ms
56,696 KB
testcase_04 AC 232 ms
59,072 KB
testcase_05 AC 156 ms
56,616 KB
testcase_06 AC 145 ms
55,988 KB
testcase_07 AC 137 ms
54,404 KB
testcase_08 AC 152 ms
56,036 KB
testcase_09 AC 151 ms
56,348 KB
testcase_10 AC 160 ms
57,016 KB
testcase_11 AC 165 ms
57,112 KB
testcase_12 AC 148 ms
55,112 KB
testcase_13 AC 187 ms
56,136 KB
testcase_14 AC 182 ms
56,744 KB
testcase_15 AC 232 ms
58,328 KB
testcase_16 AC 202 ms
56,256 KB
testcase_17 AC 226 ms
56,720 KB
testcase_18 AC 220 ms
56,548 KB
testcase_19 AC 46 ms
49,520 KB
testcase_20 AC 46 ms
49,524 KB
testcase_21 AC 48 ms
49,440 KB
testcase_22 AC 215 ms
56,752 KB
testcase_23 AC 199 ms
56,416 KB
testcase_24 AC 217 ms
56,824 KB
testcase_25 AC 198 ms
56,436 KB
testcase_26 AC 201 ms
56,168 KB
testcase_27 AC 214 ms
56,548 KB
testcase_28 AC 221 ms
56,320 KB
testcase_29 AC 220 ms
56,628 KB
testcase_30 AC 192 ms
56,932 KB
testcase_31 AC 219 ms
56,856 KB
testcase_32 AC 174 ms
56,972 KB
testcase_33 AC 178 ms
56,532 KB
testcase_34 AC 178 ms
56,512 KB
testcase_35 AC 151 ms
56,596 KB
testcase_36 AC 169 ms
56,368 KB
testcase_37 AC 171 ms
56,212 KB
testcase_38 AC 164 ms
56,316 KB
testcase_39 AC 161 ms
55,872 KB
testcase_40 AC 173 ms
56,828 KB
testcase_41 AC 172 ms
56,172 KB
testcase_42 AC 100 ms
51,888 KB
testcase_43 AC 91 ms
52,608 KB
testcase_44 AC 97 ms
51,924 KB
testcase_45 AC 96 ms
52,600 KB
testcase_46 AC 87 ms
52,076 KB
testcase_47 AC 95 ms
52,768 KB
testcase_48 AC 99 ms
52,436 KB
testcase_49 AC 80 ms
50,876 KB
testcase_50 AC 90 ms
52,420 KB
testcase_51 AC 100 ms
52,388 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