Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- static int t, p;
- static char[][] b;
- static int[] numYRow, numYCol, numYRowCurr, numYColCurr;
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- t = sc.nextInt();
- p = sc.nextInt();
- StringBuffer s = new StringBuffer();
- while(t!=0 && p!=0)
- {
- b = new char[t][p];
- /*for(int i=0; i<t; i++)
- {
- for(int j=0; j<p; j++)
- {
- b[i][j] = 'Y';
- }
- }*/
- numYRow = new int[t];
- numYCol = new int[p];
- numYRowCurr = new int[t];
- numYColCurr = new int[p];
- for(int i=0; i<t; i++)
- {
- numYRow[i] = sc.nextInt();
- //numYRowCurr[i] = p;
- }
- for(int i=0; i<p; i++)
- {
- numYCol[i] = sc.nextInt();
- //numYColCurr[i] = t;
- }
- boolean solved = solve(0);
- if(solved)
- {
- for(int i=0; i<t; i++)
- {
- for(int j=0; j<p; j++)
- {
- s.append(b[i][j]);
- }
- s.append("\n");
- }
- s.append("\n");
- }
- else
- s.append("Impossible\n\n");
- t = sc.nextInt();
- p = sc.nextInt();
- }
- System.out.println(s.substring(0,s.length()-1));
- }
- static boolean solve(int val){
- int i=val/p;
- int j=val%p;
- if(val==t*p)
- {
- return true;
- }
- if(numYRowCurr[i]+p-j-1>=numYRow[i]&&numYColCurr[j]+t-i-1>=numYCol[j])
- {
- b[i][j] = 'N';
- if(solve(val+1)) return true;
- }
- if(numYRowCurr[i]+1<=numYRow[i]&&numYColCurr[j]+1<=numYCol[j])
- {
- numYRowCurr[i]++;
- numYColCurr[j]++;
- b[i][j] = 'Y';
- if (solve(val+1)) return true;
- }
- return false;
- }
- }
Add Comment
Please, Sign In to add comment