Submission #64302

#TimeUsernameProblemLanguageResultExecution timeMemory
64302AQTBali Sculptures (APIO15_sculpture)Java
Compilation error
0 ms0 KiB
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { int N = readInt(), A = readInt(), B = readInt(); long arr[] = new long[N+1]; for(int i = 1; i<=N; i++) arr[i] = readLong(); if(A == 1) { long mask = 0; for(int i = 45; i>=0; i--) { long tempmask = mask + (1L<<i) - 1; int dp[] = new int[N+1]; Arrays.fill(dp, Integer.MAX_VALUE); dp[0] = 0; for(int j = 1; j<=N; j++) { long sum = 0; for(int k = j; k>0; k--) { sum += arr[k]; if(sum > tempmask) break; if(dp[k-1] != Integer.MAX_VALUE && (tempmask|sum) == tempmask) { dp[j] = Math.min(dp[j], dp[k-1]+1); } } } if(dp[N] > B) mask = tempmask + 1; } println(mask); } else { long mask = 0; for(int i = 45; i>=0; i--) { long tempmask = mask + (1L<<i) - 1; boolean dp[][] = new boolean[N+1][B+1]; dp[0][0] = true; for(int j = 1; j<=B; j++) { for(int k = 1; k<=N; k++) { long sum = 0; for(int l = k; l>0; l--) { sum += arr[l]; if(sum > tempmask) break; if(dp[l-1][j-1] && (tempmask|sum) == tempmask) { dp[k][j] = true; break; } } } } boolean pos = false; for(int j = A; j<=B; j++) pos |= dp[N][j]; if(!pos) mask = tempmask+1; } println(mask); } exit(); } final private static int BUFFER_SIZE = 1 << 16; private static DataInputStream din = new DataInputStream(System.in); private static byte[] buffer = new byte[BUFFER_SIZE]; private static int bufferPointer = 0, bytesRead = 0; static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); public static String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = Read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public static String read() throws IOException { byte[] ret = new byte[1024]; int idx = 0; byte c = Read(); while (c <= ' ') { c = Read(); } do { ret[idx++] = c; c = Read(); } while (c != -1 && c != ' ' && c != '\n' && c != '\r'); return new String(ret, 0, idx); } public static int readInt() throws IOException { int ret = 0; byte c = Read(); while (c <= ' ') c = Read(); boolean neg = (c == '-'); if (neg) c = Read(); do { ret = ret * 10 + c - '0'; } while ((c = Read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public static long readLong() throws IOException { long ret = 0; byte c = Read(); while (c <= ' ') c = Read(); boolean neg = (c == '-'); if (neg) c = Read(); do { ret = ret * 10 + c - '0'; } while ((c = Read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public static double readDouble() throws IOException { double ret = 0, div = 1; byte c = Read(); while (c <= ' ') c = Read(); boolean neg = (c == '-'); if (neg) c = Read(); do { ret = ret * 10 + c - '0'; } while ((c = Read()) >= '0' && c <= '9'); if (c == '.') { while ((c = Read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private static void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private static byte Read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } static void print(Object o) { pr.print(o); } static void println(Object o) { pr.println(o); } static void flush() { pr.flush(); } static void println() { pr.println(); } static void exit() throws IOException { din.close(); pr.close(); System.exit(0); } }

Compilation message (stderr)

sculpture.java:4: error: class Main is public, should be declared in a file named Main.java
public class Main {
       ^
1 error