Contest Duration: - (local time) (120 minutes)

Submission #2050060

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-1;k>=0;k--) {
int idx2 = Bound.lowerBound(a[k], INF-1) - 1;
a[k+1][idx2] = -1;
b[k+1] = Math.max(b[k+1],idx2);
}
for(int k=m;k>=0;k--) {
int idx = Bound.lowerBound(a[k], b[k], a[k].length, v[i]);
a[k][idx] = Math.min(a[k][idx], v[i]);
}
//			System.out.println(Arrays.deepToString(a));
}
int ans = 0;
for(int k=0;k<=m;k++) {
ans = Math.max(ans, Bound.lowerBound(a[k], b[k], a[k].length, INF-1) - 1);
}
System.out.println(ans);
}

}
class Bound {
static int lowerBound(int[] a,int fromIndex,int toIndex,int key) {
if (a[toIndex-1] < key) {
}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) {
}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 {
} 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();
while(isPrintableChar(b)) {
sb.appendCodePoint(b);
}
return sb.toString();
}
public char[] nextCharArray(int len) {
if (!hasNext()) {
throw new NoSuchElementException();
}
char[] s = new char[len];
int i = 0;
while(isPrintableChar(b)) {
if (i == len) {
throw new InputMismatchException();
}
s[i++] = (char) b;
}
return s;
}
public String nextLine() {
if (!hasNextLine()) {
throw new NoSuchElementException();
}
StringBuilder sb = new StringBuilder();
while(!isNewLine(b)) {
sb.appendCodePoint(b);
}
return sb.toString();
}
public long nextLong() {
if (!hasNext()) {
throw new NoSuchElementException();
}
long n = 0;
boolean minus = false;
if (b == '-') {
minus = true;
}
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();
}
}
}
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();
}
}
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 2018-02-03 17:57:38+0900 B - だんだん強く piroz95 Java8 (OpenJDK 1.8.0) 800 5649 Byte AC 820 ms 79168 KB

#### Judge Result

Set Name All
Score / Max Score 800 / 800
Status
 AC × 68
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 71 ms 19540 KB
00_sample01 AC 70 ms 15956 KB
00_sample02 AC 70 ms 20052 KB
01_minimal00 AC 69 ms 18772 KB
01_minimal01 AC 69 ms 19540 KB
01_minimal02 AC 70 ms 20564 KB
01_minimal03 AC 69 ms 15956 KB
20_small_random00 AC 70 ms 19284 KB
20_small_random01 AC 76 ms 18900 KB
20_small_random02 AC 72 ms 19028 KB
20_small_random03 AC 71 ms 19668 KB
20_small_random04 AC 72 ms 18388 KB
20_small_random05 AC 70 ms 19796 KB
20_small_random06 AC 70 ms 21460 KB
20_small_random07 AC 72 ms 23252 KB
20_small_random08 AC 75 ms 19412 KB
20_small_random09 AC 75 ms 23508 KB
20_small_random10 AC 72 ms 19028 KB
20_small_random11 AC 77 ms 21204 KB
20_small_random12 AC 75 ms 21076 KB
20_small_random13 AC 76 ms 23252 KB
20_small_random14 AC 75 ms 21460 KB
20_small_random15 AC 70 ms 18900 KB
20_small_random16 AC 71 ms 19412 KB
20_small_random17 AC 73 ms 21332 KB
20_small_random18 AC 72 ms 23252 KB
20_small_random19 AC 72 ms 18772 KB
21_small_increasing00 AC 70 ms 19412 KB
21_small_increasing01 AC 80 ms 19412 KB
21_small_increasing02 AC 71 ms 19412 KB
21_small_increasing03 AC 74 ms 18900 KB
21_small_increasing04 AC 83 ms 21204 KB
21_small_increasing05 AC 73 ms 19540 KB
22_small_decreasing00 AC 69 ms 15956 KB
22_small_decreasing01 AC 81 ms 19156 KB
22_small_decreasing02 AC 73 ms 20692 KB
22_small_decreasing03 AC 77 ms 18388 KB
22_small_decreasing04 AC 73 ms 21460 KB
22_small_decreasing05 AC 73 ms 18260 KB
23_small_mountain00 AC 69 ms 18772 KB
23_small_mountain01 AC 80 ms 18388 KB
23_small_mountain02 AC 71 ms 19284 KB
23_small_mountain03 AC 71 ms 20052 KB
23_small_mountain04 AC 74 ms 20820 KB
23_small_mountain05 AC 76 ms 20436 KB
24_small_valley00 AC 69 ms 19284 KB
24_small_valley01 AC 73 ms 21204 KB
24_small_valley02 AC 71 ms 18004 KB
24_small_valley03 AC 85 ms 21204 KB
24_small_valley04 AC 76 ms 20948 KB
24_small_valley05 AC 76 ms 21204 KB
30_large_random00 AC 530 ms 49848 KB
30_large_random01 AC 365 ms 32484 KB
30_large_random02 AC 127 ms 20596 KB
30_large_random03 AC 161 ms 21204 KB
30_large_random04 AC 390 ms 49864 KB
31_large_increasing00 AC 123 ms 21008 KB
31_large_increasing01 AC 434 ms 50904 KB
31_large_increasing02 AC 801 ms 75932 KB
32_large_decreasing00 AC 122 ms 22472 KB
32_large_decreasing01 AC 413 ms 51536 KB
32_large_decreasing02 AC 735 ms 78848 KB
33_large_mountain00 AC 124 ms 19536 KB
33_large_mountain01 AC 446 ms 50772 KB
33_large_mountain02 AC 793 ms 77384 KB
34_large_valley00 AC 129 ms 20628 KB
34_large_valley01 AC 434 ms 51040 KB
34_large_valley02 AC 820 ms 79168 KB