結果

問題 No.2210 equence Squence Seuence
ユーザー tentententen
提出日時 2023-02-14 08:47:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 340 ms / 2,000 ms
コード長 2,780 bytes
コンパイル時間 2,641 ms
コンパイル使用メモリ 87,332 KB
実行使用メモリ 62,152 KB
最終ジャッジ日時 2023-09-23 18:20:27
合計ジャッジ時間 12,301 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,436 KB
testcase_01 AC 46 ms
49,384 KB
testcase_02 AC 46 ms
49,380 KB
testcase_03 AC 176 ms
56,016 KB
testcase_04 AC 192 ms
56,008 KB
testcase_05 AC 227 ms
56,168 KB
testcase_06 AC 203 ms
55,468 KB
testcase_07 AC 284 ms
58,776 KB
testcase_08 AC 46 ms
49,424 KB
testcase_09 AC 47 ms
49,336 KB
testcase_10 AC 46 ms
49,356 KB
testcase_11 AC 45 ms
49,492 KB
testcase_12 AC 46 ms
49,428 KB
testcase_13 AC 332 ms
59,852 KB
testcase_14 AC 340 ms
59,920 KB
testcase_15 AC 332 ms
59,684 KB
testcase_16 AC 319 ms
62,152 KB
testcase_17 AC 321 ms
60,704 KB
testcase_18 AC 45 ms
47,508 KB
testcase_19 AC 45 ms
49,416 KB
testcase_20 AC 45 ms
49,376 KB
testcase_21 AC 46 ms
49,660 KB
testcase_22 AC 46 ms
49,420 KB
testcase_23 AC 282 ms
58,816 KB
testcase_24 AC 266 ms
58,268 KB
testcase_25 AC 278 ms
56,824 KB
testcase_26 AC 311 ms
61,188 KB
testcase_27 AC 193 ms
55,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt() - 1;
        int[] values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        boolean[] isLearger = new boolean[n];
        for (int i = n - 2; i >= 0; i--) {
            if (values[i] < values[i + 1]) {
                isLearger[i] = true;
            } else if (values[i] == values[i + 1]) {
                isLearger[i] = isLearger[i + 1];
            }
        }
        int ans = -1;
        int left = 0;
        int right = n - 1;
        for (int i = 0; i < n - 1; i++) {
            if (isLearger[i]) {
                if (right == k) {
                    ans = i;
                    break;
                }
                right--;
            } else {
                if (left == k) {
                    ans = i;
                    break;
                }
                left++;
            }
        }
        if (ans == -1) {
            ans = n - 1;
        }
        StringBuilder sb = new StringBuilder();
        boolean isFirst = true;
        for (int i = 0; i < n; i++) {
            if (i == ans) {
                continue;
            }
            if (!isFirst) {
                sb.append(" ");
            }
            isFirst = false;
            sb.append(values[i]);
        }
        System.out.println(sb);
    }
    
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0