Submission #696269

#TimeUsernameProblemLanguageResultExecution timeMemory
696269nicolexxuuLongest beautiful sequence (IZhO17_subsequence)Java
0 / 100
388 ms173508 KiB
import java.util.*; import java.io.*; public class subsequence { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int[] a = new int[n], k = new int[n]; st = new StringTokenizer(br.readLine()); for(int i = 0; i < n; i++) a[i] = Integer.parseInt(st.nextToken()); st = new StringTokenizer(br.readLine()); for(int i = 0; i < n; i++) k[i] = Integer.parseInt(st.nextToken()); br.close(); int[][][] dp1 = new int[1<<10][1<<10][11]; int[][][] dp2 = new int[1<<10][1<<10][11]; int[] p = new int[n]; int idx = 0, max = 0; for(int i = 0; i < n; i++) { int par = -1, ans = 0; int l = a[i] >> 10; int r = a[i] - (l << 10); for(int j = 0; j < (1 << 10); j++) { // possible prev lefts int bLeft = k[i] - Integer.bitCount(l&j); if(bLeft >= 0 && bLeft <= 10 ) { if(dp1[l][r][bLeft] > ans) { ans = dp1[l][r][bLeft]; par = dp2[l][r][bLeft]; } } } p[i] = par; ans++; if(ans > max) { max = ans; idx = i; } for(int j = 0; j < (1 << 10); j++) { int b = Integer.bitCount(j&r); if(ans+1 > dp1[l][j][b]) { dp1[l][j][b] = ans; dp2[l][j][b] = i; } } } System.out.println(max); ArrayDeque<Integer> l = new ArrayDeque<>(); while(idx != -1) { l.add(idx); idx = p[idx]; } StringBuilder sb = new StringBuilder(""); while(!l.isEmpty()) sb.append(l.pollLast()+1).append(" "); System.out.println(sb); } } /* 4 1 2 3 4 10 0 1 0 5 5 3 5 3 5 10 1 20 1 20 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...