fork download
  1. #include<iostream>
  2. #include<stack>
  3. #include<cstring>
  4. using namespace std;
  5.  
  6. struct point{
  7. int x,y;
  8. }pt;
  9. int main()
  10. {
  11. int t;
  12. long n,k;
  13. cin>>t;
  14. while(t--){
  15. cin>>n>>k;
  16. bool visited[n+1][n+1];
  17. for(long u=1;u<=n;u++)
  18. for(long v=1;v<=n;v++)
  19. visited[u][v]=false;
  20. stack<point> qu;
  21. if(!k)
  22. cout<<"0\n";
  23. else{
  24. while(k--){
  25. cin>>pt.x>>pt.y;
  26. qu.push(pt);
  27. }
  28. long c=0;
  29. while(!qu.empty()){
  30. int i=qu.top().x;
  31. int j=qu.top().y;
  32. if(!visited[i][j]){
  33. visited[i][j]=true;
  34. c++;
  35. int p=i,q=j;
  36. p--;
  37. q++;
  38. while(p>=1 && q<=n){
  39. if(!visited[p][q]){
  40. visited[p][q]=true;
  41. c++;
  42. }
  43. p--;
  44. q++;
  45. }
  46. p=i,q=j;
  47. p--;
  48. q--;
  49. while(p>=1 && q>=1){
  50. if(!visited[p][q]){
  51. visited[p][q]=true;
  52. c++;
  53. }
  54. p--;
  55. q--;
  56. }
  57. p=i,q=j;
  58. p++;
  59. q++;
  60. while(p<=n && q<=n){
  61. if(!visited[p][q]){
  62. visited[p][q]=true;
  63. c++;
  64. }
  65. p++;
  66. q++;
  67. }
  68. p=i,q=j;
  69. p++;
  70. q--;
  71. while(p<=n && q>=1){
  72. if(!visited[p][q]){
  73. visited[p][q]=true;
  74. c++;
  75. }
  76. p++;
  77. q--;
  78. }
  79. }
  80. qu.pop();
  81. }
  82. cout<<n*n-c<<"\n";
  83. }
  84. }
  85. }
  86.  
Success #stdin #stdout 0s 3280KB
stdin
1
3 2
1 2
3 2
stdout
5