QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#254235 | #7695. Double Up | billytngo | TL | 40ms | 39496kb | Java8 | 1.8kb | 2023-11-18 08:39:47 | 2023-11-18 08:39:48 |
Judging History
answer
import java.io.File;
import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.Scanner;
import java.util.Set;
import java.util.Map;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
public class Main {
private static Scanner sc;
private static Set<Integer>[][] C;
private static int getK(int v) {
// TODO Auto-generated method stub
int ret = 0;
while(v > 1) {
ret++;
v/=2;
}
return ret;
}
private static Set<Integer> possibles(List<Integer> arr,int start,int end) {
// TODO Auto-generated method stub
if(C[start][end]!=null) {
return C[start][end];
}
Set<Integer> ret = new HashSet<Integer>();
for(int i=start;i<=end;i++) {
ret.add(arr.get(i));
}
for(int i=start;i<end;i++) {
Set<Integer> arr1 = possibles(arr,start,i);
Set<Integer> arr2 = possibles(arr,i+1,end);
ret.addAll(arr1);
ret.addAll(arr2);
for(Integer v : arr1) {
if(arr2.contains(v)) {
ret.add(v+1);
}
}
}
C[start][end] = ret;
return C[start][end];
}
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
sc = new Scanner(System.in);
int n = sc.nextInt();
C = new Set[n][];
for(int i=0;i<n;i++) {
C[i] = new Set[n];
}
List<Integer> P = new ArrayList<Integer>();
for(int i=0;i<n;i++) {
int v = getK(sc.nextInt());
P.add(v);
}
Set<Integer> arr = possibles(P,0,n-1);
int m = 0;
for(Integer v : arr) {
m = Math.max(m, v);
}
BigInteger ret = new BigInteger("1");
for(int i=0;i<m;i++) {
ret = ret.multiply(new BigInteger("2"));
}
System.out.println(ret);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 40ms
memory: 39496kb
input:
5 4 2 2 1 8
output:
16
result:
ok single line: '16'
Test #2:
score: -100
Time Limit Exceeded
input:
1000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...