Submission #852225

# Submission time Handle Problem Language Result Execution time Memory
852225 2023-09-21T12:59:53 Z Trisanu_Das Zemljište (COCI22_zemljiste) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
  int r, s, a, b; cin >> r >> s >> a >> b;
  int a[r][s]; for(int i = 0; i < r; i++) for(int j = 0; j < s; j++) cin >> a[i][j];
  for(int i = 1; i < r; i++) for(int j = 0; j < s; j++) a[i][j] += a[i - 1][j];
  int ans = INT_MAX;
  for(int i = 0; i < r; i++){
    for(int j = i; j < r; j++){
      int pos = 0, sum = 0;
      for(int k = 0; k < s; k++){
        sum += a[j][k] - a[i - 1][k];
        while(sum > b && pos <= k){
          ans = min(ans, abs(b - sum) + abs(sum - a));
          sum -= a[j][pos] - a[i - 1][pos];
          pos++;
        }
        if(a <= sum && b >= sum){
          cout << b - a << '\n'; return 0;
        }
        ans = min(ans, abs(b - sum) + abs(sum - a));
      }
    }
  }
  cout << ans << '\n';
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:6:7: error: conflicting declaration 'int a [r][s]'
    6 |   int a[r][s]; for(int i = 0; i < r; i++) for(int j = 0; j < s; j++) cin >> a[i][j];
      |       ^
Main.cpp:5:13: note: previous declaration as 'int a'
    5 |   int r, s, a, b; cin >> r >> s >> a >> b;
      |             ^
Main.cpp:6:78: error: invalid types 'int[int]' for array subscript
    6 |   int a[r][s]; for(int i = 0; i < r; i++) for(int j = 0; j < s; j++) cin >> a[i][j];
      |                                                                              ^
Main.cpp:7:58: error: invalid types 'int[int]' for array subscript
    7 |   for(int i = 1; i < r; i++) for(int j = 0; j < s; j++) a[i][j] += a[i - 1][j];
      |                                                          ^
Main.cpp:7:69: error: invalid types 'int[int]' for array subscript
    7 |   for(int i = 1; i < r; i++) for(int j = 0; j < s; j++) a[i][j] += a[i - 1][j];
      |                                                                     ^
Main.cpp:13:17: error: invalid types 'int[int]' for array subscript
   13 |         sum += a[j][k] - a[i - 1][k];
      |                 ^
Main.cpp:13:27: error: invalid types 'int[int]' for array subscript
   13 |         sum += a[j][k] - a[i - 1][k];
      |                           ^
Main.cpp:16:19: error: invalid types 'int[int]' for array subscript
   16 |           sum -= a[j][pos] - a[i - 1][pos];
      |                   ^
Main.cpp:16:31: error: invalid types 'int[int]' for array subscript
   16 |           sum -= a[j][pos] - a[i - 1][pos];
      |                               ^