結果

問題 No.1765 While Shining
ユーザー tentententen
提出日時 2021-12-27 16:50:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 511 ms / 2,000 ms
コード長 1,786 bytes
コンパイル時間 2,605 ms
コンパイル使用メモリ 79,028 KB
実行使用メモリ 77,948 KB
最終ジャッジ日時 2023-10-26 02:32:24
合計ジャッジ時間 13,029 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
53,344 KB
testcase_01 AC 49 ms
53,344 KB
testcase_02 AC 49 ms
53,336 KB
testcase_03 AC 49 ms
53,332 KB
testcase_04 AC 53 ms
53,368 KB
testcase_05 AC 60 ms
53,384 KB
testcase_06 AC 56 ms
53,368 KB
testcase_07 AC 55 ms
53,356 KB
testcase_08 AC 81 ms
54,388 KB
testcase_09 AC 365 ms
67,504 KB
testcase_10 AC 498 ms
74,904 KB
testcase_11 AC 422 ms
69,144 KB
testcase_12 AC 444 ms
74,608 KB
testcase_13 AC 441 ms
73,776 KB
testcase_14 AC 489 ms
77,752 KB
testcase_15 AC 489 ms
77,708 KB
testcase_16 AC 490 ms
77,940 KB
testcase_17 AC 490 ms
75,824 KB
testcase_18 AC 503 ms
77,948 KB
testcase_19 AC 485 ms
77,660 KB
testcase_20 AC 486 ms
77,896 KB
testcase_21 AC 509 ms
76,852 KB
testcase_22 AC 484 ms
77,824 KB
testcase_23 AC 511 ms
77,216 KB
testcase_24 AC 463 ms
76,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        TreeSet<Integer> evStops = new TreeSet<>();
        TreeSet<Integer> oddStops = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            if (sc.nextInt() == 1) {
                if (i % 2 == 0) {
                    oddStops.add(i);
                } else {
                    evStops.add(i);
                }
            } else {
                if (i % 2 == 0) {
                    evStops.add(i);
                } else {
                    oddStops.add(i);
                }
            }
        }
        evStops.add(n - 1);
        oddStops.add(n - 1);
        long ans = 0;
        for (int i = 0; i < n - 1; i++) {
            if (i % 2 == 0) {
                ans += evStops.first() - i;
            } else {
                ans += oddStops.first() - i;
            }
            evStops.remove(i);
            oddStops.remove(i);
        }
        System.out.println(ans);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0