結果

問題 No.365 ジェンガソート
ユーザー discoNekodiscoNeko
提出日時 2016-04-29 22:36:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 852 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 75,096 KB
実行使用メモリ 49,188 KB
最終ジャッジ日時 2024-04-20 06:33:10
合計ジャッジ時間 8,280 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
37,132 KB
testcase_01 AC 52 ms
37,104 KB
testcase_02 AC 52 ms
36,992 KB
testcase_03 AC 53 ms
36,964 KB
testcase_04 AC 53 ms
36,968 KB
testcase_05 AC 52 ms
37,028 KB
testcase_06 AC 51 ms
37,132 KB
testcase_07 AC 53 ms
36,888 KB
testcase_08 AC 51 ms
36,976 KB
testcase_09 AC 50 ms
37,088 KB
testcase_10 AC 52 ms
36,860 KB
testcase_11 AC 50 ms
37,136 KB
testcase_12 AC 50 ms
37,088 KB
testcase_13 AC 51 ms
36,944 KB
testcase_14 AC 53 ms
36,872 KB
testcase_15 AC 51 ms
37,156 KB
testcase_16 AC 181 ms
46,408 KB
testcase_17 AC 197 ms
48,716 KB
testcase_18 AC 95 ms
39,052 KB
testcase_19 AC 216 ms
48,876 KB
testcase_20 AC 127 ms
41,612 KB
testcase_21 AC 115 ms
40,900 KB
testcase_22 AC 152 ms
46,564 KB
testcase_23 AC 138 ms
45,724 KB
testcase_24 AC 155 ms
46,144 KB
testcase_25 AC 108 ms
40,736 KB
testcase_26 AC 141 ms
45,648 KB
testcase_27 AC 219 ms
48,884 KB
testcase_28 AC 156 ms
45,280 KB
testcase_29 AC 198 ms
49,096 KB
testcase_30 AC 146 ms
46,112 KB
testcase_31 AC 122 ms
42,288 KB
testcase_32 AC 121 ms
41,620 KB
testcase_33 AC 201 ms
49,188 KB
testcase_34 AC 108 ms
40,704 KB
testcase_35 AC 191 ms
46,596 KB
testcase_36 AC 220 ms
48,924 KB
testcase_37 AC 191 ms
48,932 KB
testcase_38 AC 193 ms
49,028 KB
testcase_39 AC 201 ms
49,056 KB
testcase_40 AC 208 ms
49,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;
 
public class Main {
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();
    int n = Integer.parseInt(br.readLine());
    String[] str = br.readLine().split(" ");
    int max = 0;
    int[] a = new int [n];
    for(int i = 0; i < n; i++){
      a[i] = Integer.parseInt(str[i]);
      max = Math.max(max,a[i]);
    }
    int sum = 0;
    int chain = 0;
    for(int i = n-1; i >-1 ; i--){
      if(a[i]==max){
        sum += chain;
        chain = 0;
        max--;
      }else{
        chain++;
      }
    }
    if(chain>0)sum+=chain;
    sb.append(sum);
    System.out.println(sb);
  }
}
0