|
|
back to boardPlease can you help me why my prog gives wa3 At first I converted all the things to indices. for example if n = 5 2 4 5 2 4 and m = 1 4 2 2 -> 1 - 2, and 4 - 5 <= these are all index. Then I got only some pair of index. From these I calculate the 11011. THere may be index intersections. That is my code. I think its time and algo is ok. But I got wa3 import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Scanner; public class Timus1827 { public static void main(String [] args){ Scanner input = new Scanner(System.in); int n = input.nextInt(); int [] a = new int[n]; HashMap<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>(); for(int i = 0; i < n; i++){ a[n - i - 1] = input.nextInt(); if(map.get(a[n - i - 1]) == null){ map.put(a[n - i - 1], new ArrayList<Integer>()); } map.get(a[n - i - 1]).add(n - i - 1); } int m = input.nextInt(); int[] h = new int[n]; boolean[] dontuse = new boolean[n]; Arrays.fill(dontuse, false); Arrays.fill(h, -1); for(int i = 0; i < m; i++){ int x = input.nextInt(); int y = input.nextInt(); int d = input.nextInt() - 1; if(map.containsKey(x)) for(int j : map.get(x)){ if(j + d < n && a[j + d] == y){ h[j] = Math.max(h[j], j + d); dontuse[j] = true; } } } int k = -1; for(int i = 0; i < n; i++){ if(dontuse[i]) { k = i; break; } } int j = k; for(int i = k + 1; i < n; i++){ if(dontuse[i]){ if(h[j] + 1 >= i){ h[j] = h[i]; dontuse[i] = false; } else{ j = i; } } } int[] ans = new int[n]; Arrays.fill(ans, 0); for(int i = 0; i <n; i++){ if(dontuse[i]){ for(j = i; j <= h[i]; j++){ ans[j] = 1; } } } for (int i = 0; i < n; i++) System.out.print(ans[i]); } } I'm waiting for a favor Please somebody help me to solve this problem. Show me my mistake in algo or tell me the hint to solve it Re: I'm waiting for a favor reverse(ans.begin(), ans.end()); |
|
|