Guest User

Untitled

a guest
Jan 20th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. static int t, p;
  5. static char[][] b;
  6. static int[] numYRow, numYCol, numYRowCurr, numYColCurr;
  7.  
  8. public static void main(String[] args) {
  9. Scanner sc = new Scanner(System.in);
  10. t = sc.nextInt();
  11. p = sc.nextInt();
  12. StringBuffer s = new StringBuffer();
  13. while(t!=0 && p!=0)
  14. {
  15. b = new char[t][p];
  16. /*for(int i=0; i<t; i++)
  17. {
  18. for(int j=0; j<p; j++)
  19. {
  20. b[i][j] = 'Y';
  21. }
  22. }*/
  23. numYRow = new int[t];
  24. numYCol = new int[p];
  25. numYRowCurr = new int[t];
  26. numYColCurr = new int[p];
  27. for(int i=0; i<t; i++)
  28. {
  29. numYRow[i] = sc.nextInt();
  30. //numYRowCurr[i] = p;
  31. }
  32. for(int i=0; i<p; i++)
  33. {
  34. numYCol[i] = sc.nextInt();
  35. //numYColCurr[i] = t;
  36. }
  37.  
  38. boolean solved = solve(0);
  39.  
  40. if(solved)
  41. {
  42. for(int i=0; i<t; i++)
  43. {
  44. for(int j=0; j<p; j++)
  45. {
  46. s.append(b[i][j]);
  47. }
  48. s.append("\n");
  49. }
  50. s.append("\n");
  51. }
  52. else
  53. s.append("Impossible\n\n");
  54. t = sc.nextInt();
  55. p = sc.nextInt();
  56. }
  57. System.out.println(s.substring(0,s.length()-1));
  58. }
  59.  
  60. static boolean solve(int val){
  61. int i=val/p;
  62. int j=val%p;
  63. if(val==t*p)
  64. {
  65. return true;
  66. }
  67. if(numYRowCurr[i]+p-j-1>=numYRow[i]&&numYColCurr[j]+t-i-1>=numYCol[j])
  68. {
  69. b[i][j] = 'N';
  70. if(solve(val+1)) return true;
  71. }
  72. if(numYRowCurr[i]+1<=numYRow[i]&&numYColCurr[j]+1<=numYCol[j])
  73. {
  74. numYRowCurr[i]++;
  75. numYColCurr[j]++;
  76. b[i][j] = 'Y';
  77. if (solve(val+1)) return true;
  78. }
  79.  
  80. return false;
  81. }
  82. }
Add Comment
Please, Sign In to add comment