結果

問題 No.365 ジェンガソート
ユーザー discoNekodiscoNeko
提出日時 2016-04-29 22:36:22
言語 Java19
(openjdk 21)
結果
AC  
実行時間 197 ms / 2,000 ms
コード長 852 bytes
コンパイル時間 2,160 ms
コンパイル使用メモリ 72,144 KB
実行使用メモリ 61,056 KB
最終ジャッジ日時 2023-08-02 06:42:29
合計ジャッジ時間 8,809 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,640 KB
testcase_01 AC 43 ms
49,552 KB
testcase_02 AC 43 ms
49,256 KB
testcase_03 AC 43 ms
49,332 KB
testcase_04 AC 42 ms
49,176 KB
testcase_05 AC 42 ms
49,240 KB
testcase_06 AC 43 ms
49,092 KB
testcase_07 AC 43 ms
49,100 KB
testcase_08 AC 46 ms
49,288 KB
testcase_09 AC 44 ms
49,688 KB
testcase_10 AC 43 ms
49,276 KB
testcase_11 AC 43 ms
49,168 KB
testcase_12 AC 43 ms
49,236 KB
testcase_13 AC 43 ms
49,192 KB
testcase_14 AC 43 ms
49,256 KB
testcase_15 AC 42 ms
49,396 KB
testcase_16 AC 172 ms
56,392 KB
testcase_17 AC 185 ms
60,996 KB
testcase_18 AC 83 ms
52,324 KB
testcase_19 AC 190 ms
60,500 KB
testcase_20 AC 107 ms
54,664 KB
testcase_21 AC 108 ms
54,596 KB
testcase_22 AC 179 ms
55,980 KB
testcase_23 AC 139 ms
56,968 KB
testcase_24 AC 160 ms
55,692 KB
testcase_25 AC 105 ms
54,352 KB
testcase_26 AC 146 ms
55,032 KB
testcase_27 AC 197 ms
61,056 KB
testcase_28 AC 152 ms
55,552 KB
testcase_29 AC 181 ms
58,256 KB
testcase_30 AC 155 ms
55,888 KB
testcase_31 AC 113 ms
54,564 KB
testcase_32 AC 112 ms
54,500 KB
testcase_33 AC 193 ms
60,664 KB
testcase_34 AC 99 ms
52,148 KB
testcase_35 AC 175 ms
56,680 KB
testcase_36 AC 195 ms
60,204 KB
testcase_37 AC 173 ms
60,448 KB
testcase_38 AC 182 ms
60,904 KB
testcase_39 AC 194 ms
60,372 KB
testcase_40 AC 178 ms
60,328 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