結果

問題 No.921 ずんだアロー
ユーザー 37zigen37zigen
提出日時 2020-03-18 18:50:49
言語 Java19
(openjdk 21)
結果
AC  
実行時間 446 ms / 2,000 ms
コード長 2,920 bytes
コンパイル時間 2,547 ms
コンパイル使用メモリ 75,720 KB
実行使用メモリ 60,708 KB
最終ジャッジ日時 2023-08-20 20:10:13
合計ジャッジ時間 10,084 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
55,416 KB
testcase_01 AC 102 ms
55,804 KB
testcase_02 AC 105 ms
55,968 KB
testcase_03 AC 102 ms
56,044 KB
testcase_04 AC 105 ms
55,880 KB
testcase_05 AC 110 ms
55,832 KB
testcase_06 AC 132 ms
55,916 KB
testcase_07 AC 114 ms
55,696 KB
testcase_08 AC 108 ms
55,412 KB
testcase_09 AC 111 ms
55,780 KB
testcase_10 AC 426 ms
60,708 KB
testcase_11 AC 410 ms
60,584 KB
testcase_12 AC 258 ms
60,156 KB
testcase_13 AC 407 ms
60,432 KB
testcase_14 AC 386 ms
60,124 KB
testcase_15 AC 351 ms
60,276 KB
testcase_16 AC 203 ms
59,828 KB
testcase_17 AC 415 ms
60,036 KB
testcase_18 AC 437 ms
60,400 KB
testcase_19 AC 422 ms
60,536 KB
testcase_20 AC 421 ms
60,148 KB
testcase_21 AC 414 ms
60,312 KB
testcase_22 AC 427 ms
60,136 KB
testcase_23 AC 408 ms
60,660 KB
testcase_24 AC 446 ms
60,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	long f(char[] n4) {
		long ret=0;
		long a=1;
		for(int i=0;i<n4.length;++i,a=a*4%15) {
			ret+=(n4[i]-'0')*a%15;
		}
		return ret;
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;++i)a[i]=sc.nextInt();
		int[] dp=new int[n];
		for(int i=0;i<n;++i) {
			if(i>0)dp[i]=dp[i-1];
			dp[i]=Math.max(dp[i],(i-2>=0?dp[i-2]:0)+1);
			if(i>0&&a[i]==a[i-1])dp[i]=Math.max(dp[i], dp[i-1]+1);
		}
		System.out.println(dp[n-1]);
	}

	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    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;}
    public 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());}
}
0