fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n, m, k;
  7. cin >> n >> m >> k;
  8.  
  9. vector<vector<int>> a(n, vector<int>(m));
  10.  
  11. for (int i = 0; i < n; ++i){
  12. for (int j = 0; j < m; ++j){
  13. int g;
  14. cin >> g;
  15. a[i][j]=g;
  16. }
  17. }
  18.  
  19. int ans = -1;
  20.  
  21. for (int i = 0; i < n; ++i){
  22. for (int j = 0; j <= m - k; ++j){
  23. int s;
  24. s = 0;
  25. for (int x = j; x < j + k; ++x){
  26. if (a[i][x] == 0){
  27. s++;
  28. }
  29. }
  30. if (s == k){
  31. ans = i;
  32. break;
  33. }
  34. }
  35.  
  36. if (ans >= 0){
  37. break;
  38. }
  39. }
  40. if (ans >= 0){
  41. cout << ans+1;
  42. }
  43. else{
  44. cout << 0;
  45. }
  46. return 0;
  47. }
  48.  
  49.  
Success #stdin #stdout 0.01s 5300KB
stdin
3
4
2
1 0 0 1
0 0 0 1
1 1 1 0
stdout
1