結果

問題 No.2757 Pin Game
ユーザー AsahiAsahi
提出日時 2024-05-20 02:26:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 8,587 bytes
コンパイル時間 3,097 ms
コンパイル使用メモリ 92,100 KB
実行使用メモリ 57,020 KB
最終ジャッジ日時 2024-05-20 02:26:39
合計ジャッジ時間 6,362 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
54,396 KB
testcase_01 AC 132 ms
54,172 KB
testcase_02 AC 132 ms
53,972 KB
testcase_03 AC 136 ms
53,988 KB
testcase_04 AC 238 ms
57,020 KB
testcase_05 AC 211 ms
56,900 KB
testcase_06 AC 132 ms
54,284 KB
testcase_07 AC 133 ms
54,132 KB
testcase_08 AC 135 ms
54,244 KB
testcase_09 AC 136 ms
54,164 KB
testcase_10 AC 204 ms
54,780 KB
testcase_11 AC 196 ms
54,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main implements Runnable 
{

    public void solve(InputOutput io) 
    { 
        int n = io.nextInt() , k = io.nextInt();
        int [] x = io.nextInt(n);
        long pre = x[0];
        int ans = 1;
        for(int i = 1 ; i < n ; i ++)
        {
            if(x[i] - pre >= k)
                pre = x[i];
            else 
                continue;
            ans++;
        }
        io.print(ans);
    }

    public static void main(String [] args) 
    { 
        new Thread(null, new Main(), "", Runtime.getRuntime().maxMemory()).start() ; 
    }

    @Override
    public void run() 
    { 
        InputOutput io  = new InputOutput();
        solve(io); 
        io.flush(); 
    }   


}

class InputOutput extends PrintWriter {

    private final InputStream in = System.in ;
    private final Scanner sc = new Scanner(System.in);
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    InputOutput() {
        super(System.out);
    }

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { 
        if (hasNextByte()) return buffer[ptr++]; else return -1;
    }

    private static boolean isPrintableChar(int c) { 
        return 33 <= c && c <= 126;
    }

    private boolean hasNext() { 
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++; 
        }
        return hasNextByte();
    }
    
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() { 
        return Double.parseDouble(next());
    }

    public char nextChar() {
        return next().charAt(0);
    }

    public BigInteger nextBigInteger() {
        return sc.nextBigInteger();
    }

    public int [] nextInt(int n) {
        int [] array = new int[n];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = nextInt();
        }
        return array ;
    }

    public int [][] nextInt(int n , int m) {
        int [][] array = new int[n][m];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = nextInt(m);
        }
        return array ;
    }

    public long [] nextLong(int n) {
        long [] array = new long[n];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = nextLong();
        }
        return array ;
    }

    public long [][] nextLong(int n , int m) {
        long [][] array = new long[n][m];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = nextLong(m);
        }
        return array ;
    }

    public double [] nextDouble(int n) {
        double [] array = new double[n];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = nextDouble();
        }
        return array ;
    }
    
    public String [] next(int n) {
        String [] array = new String[n];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = next();
        }
        return array ;
    }

    public String [][] next(int n , int m) {
        String [][] array = new String[n][m];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = next(m);
        }
        return array ;
    }

    public char [] nextChar(int n) {
        return next().toCharArray();
    }

    public char [][] nextChar(int n , int m) {
        char [][] array = new char[n][m];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = nextChar(m);
        }
        return array ;
    }

    public void yes() {
        println("Yes");
    }

    public void no() {
        println("No");
    }

    public void yesno(boolean bool) {
        if(bool) yes();
        else no();
    }

    public void print(Object...obj) {
        for(Object o : obj) print(o+" ");
    }

    public void println(Object...obj) {
        for(Object o : obj) print(o+" ");
        println();
    }

    public void print(int [] array) {
        StringBuilder ret = new StringBuilder();
        for(var a : array) ret.append(a +" ");
        System.out.println(ret);
    }

    public void print(long [] array) {
        StringBuilder ret = new StringBuilder();
        for(var a : array) ret.append(a +" ");
        System.out.println(ret);
    }

    public void print(double [] array) {
        StringBuilder ret = new StringBuilder();
        for(var a : array) ret.append(a +" ");
        System.out.println(ret);
    }

    public void print(String [] array) {
        StringBuilder ret = new StringBuilder();
        for(var a : array) ret.append(a +" ");
        System.out.println(ret);
    }

    public void print(char [] array) {
        StringBuilder ret = new StringBuilder();
        for(var a : array) ret.append(a +" ");
        System.out.println(ret);
    }

    public void print(boolean [] array) {
        StringBuilder ret = new StringBuilder();
        for(var a : array) ret.append(a +" ");
        System.out.println(ret);
    }

    public void print(int [][] array) {
        for(var arr : array) println(arr);
    }

    public void print(long [][] array) {
        for(var arr : array) println(arr);
    }

    public void print(double [][] array) {
        for(var arr : array) println(arr);
    }

    public void print(String [][] array) {
        for(var arr : array) println(arr);
    }

    public void print(char [][] array) {
        for(var arr : array) println(arr);
    }

    public void print(boolean [][] array) {
        for(var arr : array) println(arr);
    }

    public void println(int [] array) {
        StringBuilder ret = new StringBuilder();
        for(var a : array) ret.append(a +" ");
        System.out.println(ret);
    }

    public void println(long [] array) {
        StringBuilder ret = new StringBuilder();
        for(var a : array) ret.append(a +" ");
        System.out.println(ret);
    }

    public void println(double [] array) {
        StringBuilder ret = new StringBuilder();
        for(var a : array) ret.append(a +" ");
        System.out.println(ret);
    }

    public void println(String [] array) {
        StringBuilder ret = new StringBuilder();
        for(var a : array) ret.append(a +" ");
        System.out.println(ret);
    }

    public void println(char [] array) {
        StringBuilder ret = new StringBuilder();
        for(var a : array) ret.append(a +" ");
        System.out.println(ret);
    }

    public void println(boolean [] array) {
        StringBuilder ret = new StringBuilder();
        for(var a : array) ret.append(a +" ");
        System.out.println(ret);
    }

    public void println(int [][] array) {
        for(var arr : array) println(arr);
    }

    public void println(long [][] array) {
        for(var arr : array) println(arr);
    }

    public void println(double [][] array) {
        for(var arr : array) println(arr);
    }

    public void println(String [][] array) {
        for(var arr : array) println(arr);
    }

    public void println(char [][] array) {
        for(var arr : array) println(arr);
    }

    public void println(boolean [][] array) {
        for(var arr : array) println(arr);
    }

}
0