fork(1) download
  1. #include <cstdio>
  2. #include <vector>
  3. #include <deque>
  4. #include <queue>
  5. #include <map>
  6. #include <set>
  7. #include <algorithm>
  8. #include <functional>
  9. #include <numeric>
  10. #include <iostream>
  11. #include <string>
  12. #include <cmath>
  13.  
  14. using namespace std;
  15. typedef long long ll;
  16.  
  17. void printCell(vector< vector<int> > &cell, int H, int W){
  18. cout << "-----" << endl;
  19. for(int h= 0; h < H; ++h){
  20. for(int w = 0; w < W; ++w){
  21. printf("%03d ", cell[h][w]);
  22. }
  23. cout << endl;
  24. }
  25. cout << "-----" << endl;
  26. }
  27.  
  28.  
  29. int main(void)
  30. {
  31. int T;
  32. cin >> T;
  33.  
  34. for(int t = 0; t < T; ++t){
  35. int H, W;
  36. cin >> H >> W;
  37.  
  38. vector< vector<int> > cell(H, vector<int>(W));
  39. for(int h= 0; h < H; ++h){
  40. for(int w = 0; w < W; ++w){
  41. cin >> cell[h][w];
  42. }
  43. }
  44. //printCell(cell, H, W);
  45.  
  46. vector< vector<int> > cell2(H, vector<int>(W));
  47. for(int h= 0; h < H; ++h){
  48. for(int w = 0; w < W; ++w){
  49. cell2[h][w] = 100;
  50. }
  51. }
  52.  
  53. for(int h = 0; h < H; ++h){
  54. int highest = -1;
  55. for(int w = 0; w < W; ++w){
  56. highest = max(highest, cell[h][w]);
  57. }
  58. for(int w = 0; w < W; ++w){
  59. cell2[h][w] = min(highest, cell2[h][w]);
  60. }
  61. }
  62.  
  63. for(int w = 0; w < W; ++w){
  64. int highest = -1;
  65. for(int h = 0; h < H; ++h){
  66. highest = max(highest, cell[h][w]);
  67. }
  68. for(int h = 0; h < H; ++h){
  69. cell2[h][w] = min(highest, cell2[h][w]);
  70. }
  71. }
  72. //printCell(cell2, H, W);
  73.  
  74. string ans = "YES";
  75. for(int h= 0; h < H; ++h){
  76. for(int w = 0; w < W; ++w){
  77. if (cell[h][w] != cell2[h][w]){
  78. ans = "NO";
  79. break;
  80. }
  81. }
  82. }
  83.  
  84. cout << "Case #" << (t+1) << ": " << ans << endl;
  85. }
  86.  
  87. return 0;
  88. }
  89.  
Runtime error #stdin #stdout #stderr 0.43s 529408KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc