Submission #2050002


Source Code Expand

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];
		int[] b = new int[m+1];
		for(int i=0;i<=m;i++) {
			Arrays.fill(a[i], INF);
			a[i][0] = -1;
		}
		Arrays.fill(b, 0);
		for(int i=0;i<n;i++) {
			for(int k=m;k>=0;k--) {
				int idx = Bound.lowerBound(a[k], b[k], a[k].length, v[i]);
				int idx2 = Bound.lowerBound(a[k], INF-1);
				a[k][idx] = Math.min(a[k][idx], v[i]);
				if (k < m) {
					a[k+1][idx2] = -1;
					b[k+1] = idx2;
				}
			}
//			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) {}}
}

Submission Info

Submission Time
Task B - だんだん強く
User piroz95
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 5531 Byte
Status WA
Exec Time 959 ms
Memory 80968 KB

Judge Result

Set Name All
Score / Max Score 0 / 800
Status
AC × 39
WA × 29
Set Name Test Cases
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
Case Name Status Exec Time Memory
00_sample00 AC 72 ms 21460 KB
00_sample01 AC 69 ms 20820 KB
00_sample02 AC 70 ms 23380 KB
01_minimal00 AC 70 ms 19284 KB
01_minimal01 AC 69 ms 18260 KB
01_minimal02 AC 69 ms 21076 KB
01_minimal03 AC 71 ms 21204 KB
20_small_random00 WA 73 ms 19412 KB
20_small_random01 AC 75 ms 18900 KB
20_small_random02 WA 71 ms 18388 KB
20_small_random03 AC 72 ms 18516 KB
20_small_random04 WA 70 ms 17748 KB
20_small_random05 WA 72 ms 18260 KB
20_small_random06 WA 72 ms 18388 KB
20_small_random07 WA 73 ms 19412 KB
20_small_random08 AC 73 ms 19540 KB
20_small_random09 AC 83 ms 21460 KB
20_small_random10 WA 73 ms 19156 KB
20_small_random11 AC 73 ms 19028 KB
20_small_random12 AC 73 ms 18900 KB
20_small_random13 AC 74 ms 19156 KB
20_small_random14 AC 71 ms 18260 KB
20_small_random15 WA 73 ms 20692 KB
20_small_random16 WA 72 ms 18132 KB
20_small_random17 AC 76 ms 19540 KB
20_small_random18 WA 74 ms 21076 KB
20_small_random19 WA 73 ms 21204 KB
21_small_increasing00 AC 73 ms 19028 KB
21_small_increasing01 AC 74 ms 18900 KB
21_small_increasing02 AC 72 ms 19284 KB
21_small_increasing03 AC 75 ms 20564 KB
21_small_increasing04 AC 74 ms 19796 KB
21_small_increasing05 AC 76 ms 19028 KB
22_small_decreasing00 AC 69 ms 21076 KB
22_small_decreasing01 WA 80 ms 17876 KB
22_small_decreasing02 WA 73 ms 21076 KB
22_small_decreasing03 WA 77 ms 19284 KB
22_small_decreasing04 WA 74 ms 19028 KB
22_small_decreasing05 AC 74 ms 19156 KB
23_small_mountain00 AC 70 ms 19156 KB
23_small_mountain01 WA 81 ms 19284 KB
23_small_mountain02 WA 73 ms 19924 KB
23_small_mountain03 AC 75 ms 20820 KB
23_small_mountain04 AC 77 ms 18516 KB
23_small_mountain05 AC 73 ms 21460 KB
24_small_valley00 AC 70 ms 19924 KB
24_small_valley01 WA 81 ms 18004 KB
24_small_valley02 WA 73 ms 19156 KB
24_small_valley03 AC 75 ms 18132 KB
24_small_valley04 AC 133 ms 19412 KB
24_small_valley05 AC 76 ms 20308 KB
30_large_random00 WA 697 ms 51144 KB
30_large_random01 WA 470 ms 32652 KB
30_large_random02 AC 120 ms 20568 KB
30_large_random03 WA 177 ms 26440 KB
30_large_random04 WA 541 ms 49748 KB
31_large_increasing00 AC 120 ms 20544 KB
31_large_increasing01 AC 461 ms 47576 KB
31_large_increasing02 AC 819 ms 77196 KB
32_large_decreasing00 AC 128 ms 20696 KB
32_large_decreasing01 WA 441 ms 48472 KB
32_large_decreasing02 WA 874 ms 79116 KB
33_large_mountain00 AC 120 ms 20568 KB
33_large_mountain01 WA 468 ms 51392 KB
33_large_mountain02 WA 896 ms 80968 KB
34_large_valley00 AC 120 ms 22744 KB
34_large_valley01 WA 486 ms 51032 KB
34_large_valley02 WA 959 ms 76444 KB