提出 #2049940


ソースコード 拡げる

Copy
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {
	public static final int INF = Integer.MAX_VALUE - 10;
	public static void main(String[] args) {
		IO io = new IO();
		int n = io.nextInt();
		int m = io.nextInt();
		int[] v = io.nextIntArray(n);
		int[][] a = new int[m+1][n+5];
		for(int i=0;i<=m;i++) {
			Arrays.fill(a[i], INF);
			a[i][0] = -1;
		}
		for(int i=0;i<n;i++) {
			for(int k=m;k>=0;k--) {
				int idx = Bound.lowerBound(a[k], v[i]);
				int idx2 = Bound.upperBound(a[k], INF-1);
				a[k][idx] = Math.min(a[k][idx], v[i]);
				if (k < m) {
					a[k+1][idx2+1] = -1;
				}
			}
//			System.out.println(Arrays.deepToString(a));
		}
		System.out.println(Bound.upperBound(a[Math.min(n, m)], INF-1));
	}

}
class Bound {
	static int lowerBound(int[] a,int fromIndex,int toIndex,int key) {
		if (a[toIndex-1] < key) {
			return toIndex;
		}else if(a[fromIndex] >= key) {
			return fromIndex;
		}
		int l = fromIndex;
		int r = toIndex - 1;
		while(l + 1 < r) {
			int c = (l + r) >>> 1;
			if (a[c] >= key) {
				r = c;
			}else{
				l = c;
			}
		}
		return r;
	}
	static int lowerBound(int[] a,int key) {
		return lowerBound(a, 0, a.length, key);
	}
	static int upperBound(int[] a,int fromIndex,int toIndex,int key) {
		if (a[toIndex-1] <= key) {
			return toIndex - 1;
		}else if(a[fromIndex] > key) {
			return fromIndex - 1;
		}
		int l = fromIndex;
		int r = toIndex - 1;
		while(l + 1 < r) {
			int c = (l + r) >>> 1;
			if (a[c] > key) {
				r = c;
			}else{
				l = c;
			}
		}
		return l;
	}
	static int upperBound(int[] a,int key) {
		return upperBound(a, 0, a.length, key);
	}
}

class IO extends PrintWriter {
	private final InputStream in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	public IO() { this(System.in);}
	public IO(InputStream source) { super(System.out); this.in = source;}
	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 static boolean isNewLine(int c) { return c == '\n' || c == '\r';}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public boolean hasNextLine() { while(hasNextByte() && isNewLine(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 char[] nextCharArray(int len) {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		char[] s = new char[len];
		int i = 0;
		int b = readByte();
		while(isPrintableChar(b)) {
			if (i == len) {
				throw new InputMismatchException();
			}
			s[i++] = (char) b;
			b = readByte();
		}
		return s;
	}
	public String nextLine() {
		if (!hasNextLine()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(!isNewLine(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 char nextChar() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		return (char) readByte();
	}
	public double nextDouble() { return Double.parseDouble(next());}
	public int[] nextIntArray(int n) { int[] a = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a;}
	public long[] nextLongArray(int n) { long[] a = new long[n]; for(int i=0;i<n;i++) a[i] = nextLong(); return a;}
	public double[] nextDoubleArray(int n) { double[] a = new double[n]; for(int i=0;i<n;i++) a[i] = nextDouble(); return a;}
	public void nextIntArrays(int[]... a) { for(int i=0;i<a[0].length;i++) for(int j=0;j<a.length;j++) a[j][i] = nextInt();}
	public int[][] nextIntMatrix(int n,int m) { int[][] a = new int[n][]; for(int i=0;i<n;i++) a[i] = nextIntArray(m); return a;}
	public char[][] nextCharMap(int n,int m) { char[][] a = new char[n][]; for(int i=0;i<n;i++) a[i] = nextCharArray(m); return a;}
	public void close() { super.close(); try {in.close();} catch (IOException e) {}}
}

提出情報

提出日時
問題 B - だんだん強く
ユーザ piroz95
言語 Java8 (OpenJDK 1.8.0)
得点 0
コード長 5444 Byte
結果 WA
実行時間 1012 ms
メモリ 81116 KB

ジャッジ結果

セット名 All
得点 / 配点 0 / 800
結果
AC × 39
WA × 29
セット名 テストケース
All 00_sample00, 00_sample01, 00_sample02, 01_minimal00, 01_minimal01, 01_minimal02, 01_minimal03, 20_small_random00, 20_small_random01, 20_small_random02, 20_small_random03, 20_small_random04, 20_small_random05, 20_small_random06, 20_small_random07, 20_small_random08, 20_small_random09, 20_small_random10, 20_small_random11, 20_small_random12, 20_small_random13, 20_small_random14, 20_small_random15, 20_small_random16, 20_small_random17, 20_small_random18, 20_small_random19, 21_small_increasing00, 21_small_increasing01, 21_small_increasing02, 21_small_increasing03, 21_small_increasing04, 21_small_increasing05, 22_small_decreasing00, 22_small_decreasing01, 22_small_decreasing02, 22_small_decreasing03, 22_small_decreasing04, 22_small_decreasing05, 23_small_mountain00, 23_small_mountain01, 23_small_mountain02, 23_small_mountain03, 23_small_mountain04, 23_small_mountain05, 24_small_valley00, 24_small_valley01, 24_small_valley02, 24_small_valley03, 24_small_valley04, 24_small_valley05, 30_large_random00, 30_large_random01, 30_large_random02, 30_large_random03, 30_large_random04, 31_large_increasing00, 31_large_increasing01, 31_large_increasing02, 32_large_decreasing00, 32_large_decreasing01, 32_large_decreasing02, 33_large_mountain00, 33_large_mountain01, 33_large_mountain02, 34_large_valley00, 34_large_valley01, 34_large_valley02
ケース名 結果 実行時間 メモリ
00_sample00 AC 72 ms 21716 KB
00_sample01 AC 69 ms 19668 KB
00_sample02 AC 70 ms 21204 KB
01_minimal00 AC 68 ms 19924 KB
01_minimal01 AC 69 ms 21332 KB
01_minimal02 AC 70 ms 20692 KB
01_minimal03 AC 68 ms 21076 KB
20_small_random00 WA 84 ms 23380 KB
20_small_random01 AC 84 ms 19412 KB
20_small_random02 WA 84 ms 19156 KB
20_small_random03 AC 86 ms 21332 KB
20_small_random04 WA 82 ms 19412 KB
20_small_random05 WA 82 ms 19412 KB
20_small_random06 WA 80 ms 21204 KB
20_small_random07 WA 71 ms 18260 KB
20_small_random08 AC 83 ms 18388 KB
20_small_random09 AC 77 ms 21204 KB
20_small_random10 WA 73 ms 21332 KB
20_small_random11 AC 82 ms 19412 KB
20_small_random12 AC 76 ms 21460 KB
20_small_random13 AC 77 ms 21204 KB
20_small_random14 AC 82 ms 19540 KB
20_small_random15 WA 80 ms 19412 KB
20_small_random16 WA 82 ms 22996 KB
20_small_random17 AC 84 ms 18644 KB
20_small_random18 WA 72 ms 21332 KB
20_small_random19 WA 83 ms 21332 KB
21_small_increasing00 AC 69 ms 21204 KB
21_small_increasing01 AC 70 ms 19156 KB
21_small_increasing02 AC 73 ms 18260 KB
21_small_increasing03 AC 83 ms 19540 KB
21_small_increasing04 AC 75 ms 18516 KB
21_small_increasing05 AC 84 ms 19412 KB
22_small_decreasing00 AC 68 ms 21332 KB
22_small_decreasing01 WA 71 ms 18772 KB
22_small_decreasing02 WA 82 ms 19156 KB
22_small_decreasing03 WA 85 ms 19028 KB
22_small_decreasing04 WA 82 ms 19412 KB
22_small_decreasing05 AC 83 ms 19668 KB
23_small_mountain00 AC 69 ms 15828 KB
23_small_mountain01 WA 72 ms 19028 KB
23_small_mountain02 WA 81 ms 21332 KB
23_small_mountain03 AC 84 ms 19156 KB
23_small_mountain04 AC 75 ms 20180 KB
23_small_mountain05 AC 86 ms 19284 KB
24_small_valley00 AC 71 ms 20944 KB
24_small_valley01 WA 70 ms 19156 KB
24_small_valley02 WA 83 ms 18388 KB
24_small_valley03 AC 84 ms 20052 KB
24_small_valley04 AC 76 ms 19412 KB
24_small_valley05 AC 83 ms 19412 KB
30_large_random00 WA 788 ms 50880 KB
30_large_random01 WA 500 ms 32712 KB
30_large_random02 AC 123 ms 20696 KB
30_large_random03 WA 180 ms 22616 KB
30_large_random04 WA 639 ms 52040 KB
31_large_increasing00 AC 136 ms 20824 KB
31_large_increasing01 AC 447 ms 52312 KB
31_large_increasing02 AC 735 ms 80972 KB
32_large_decreasing00 AC 129 ms 19724 KB
32_large_decreasing01 WA 447 ms 50888 KB
32_large_decreasing02 WA 801 ms 80968 KB
33_large_mountain00 AC 121 ms 21952 KB
33_large_mountain01 WA 447 ms 52692 KB
33_large_mountain02 WA 751 ms 77708 KB
34_large_valley00 AC 131 ms 20824 KB
34_large_valley01 WA 465 ms 52944 KB
34_large_valley02 WA 1012 ms 81116 KB