Advertisement
a53

splatoon

a53
Jan 17th, 2021
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include <cstdio>
  2. using namespace std;
  3. int dx[10]={0,-1,-1,-1,0,0,1,1,1,0};
  4. int dy[10]={0,-1,0,1,-1,1,-1,0,1,0};
  5. int a[1505][1505],b[1505][1505],N, M, Q, i, j;
  6. int x, y, q[2300005][2], d[1505],s[1505],p,u,l,c,nr,max1;
  7.  
  8. int main()
  9. {
  10. scanf("%d\n",&N);
  11. for (i=1;i<=N; i++)
  12. for (j=1; j<=N; j++)
  13. scanf("%d",&a[i][j]),b[i][j]=N+1;
  14. scanf("%d\n", &M);
  15. nr=0;
  16. for (i=1 ;i<= M; i++)
  17. {
  18. scanf("%d%d\n",&x,&y);
  19. if (a[x][y]==1) nr++;
  20. b[x][y]=0;
  21. q[i][0]=x;
  22. q[i][1]=y;
  23. }
  24. p=1;
  25. u=M;
  26. while (p<=u)
  27. {
  28. x=q[p][0];
  29. y=q[p][1];
  30. for (i=1;i<=8;i++)
  31. {
  32. l=x+dx[i];
  33. c=y+dy[i];
  34. if (l>=1&&l<=N&&c>=1&&c<=N&&b[l][c]>b[x][y]+1)
  35. b[l][c]=b[x][y]+1, u++, q[u][0]=l, q[u][1]=c;
  36. }
  37. p++;
  38. }
  39. max1=-1;
  40. for (i=1;i<=N;i++)
  41. {
  42. for (j=1;j<=N;j++)
  43. {
  44. if (a[i][j]==0)d[b[i][j]]++;
  45. if (a[i][j]==0&&b[i][j]>max1&&b[i][j]<=N) max1=b[i][j];
  46. }
  47. }
  48. d[0]=M-nr;
  49. s[0]=d[0];
  50. for (i=1;i<=max1;i++)
  51. s[i]=s[i-1]+d[i];
  52. scanf("%d\n",&Q);
  53. int tt,zz,yy,qq=0;
  54. for (i=1;i<=Q;i++)
  55. {
  56. scanf("%d",&x);
  57. p=0;
  58. u=max1;
  59. if (s[0]>=x) {printf("0 ");qq=qq+2;}
  60. else
  61. if (x>s[u])
  62. {printf("-1 ");qq==qq+3;}
  63. else
  64. {
  65. int rez=N*N+1;
  66. while (p<=u)
  67. {
  68. int mij=(p+u)/2;
  69. if (s[mij]>=x)
  70. {
  71. rez=mij;
  72. u=mij-1;
  73. }
  74. else
  75. if (s[mij]<x)
  76. p=mij+1;
  77. }
  78. printf("%d ",rez);
  79. }
  80. }
  81. return 0;
  82.  
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement