fork download
  1. #include <memory.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main() {
  6. int N; cin>>N;
  7. while(N--){
  8. //input
  9. int n,m; cin>>n>>m;
  10. int stu[n+2][m+2]; memset(stu,0,sizeof(stu));
  11. int L; cin>>L;
  12. for(int i=0;i<L;i++){
  13. int x,y; cin>>x>>y;
  14.  
  15. //share with neighbor
  16. stu[x-1][y]=1;
  17. stu[x+1][y]=1;
  18. stu[x][y]=1;
  19. stu[x][y-1]=1;
  20. stu[x][y+1]=1;
  21. }
  22.  
  23. //check weather all neighbor get candy or not
  24. int all_student_get_candy=1;
  25. for(int row=1;row<n+1;row++){
  26. for(int col=1;col<m+1;col++){
  27. if(stu[row][col]==0){
  28. all_student_get_candy=0;
  29. }
  30. }
  31. }
  32.  
  33. //output
  34. if(all_student_get_candy){
  35. cout<<"Y"<<endl;
  36. }else{
  37. cout<<"N"<<endl;
  38. }
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0s 15240KB
stdin
3
2 3 1
1 1
4 3 4
1 2
2 2
3 2
4 2
5 4 5
1 3
2 1
3 4
4 1
5 3
stdout
N
Y
N