CSES - Leirikisa 1 - Results
Submission details
Task:ratar
Sender:Kuha
Submission time:2016-07-27 16:06:07 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:38:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (ll y = 0; y < n; y++) {
                      ^
input/code.cpp:39:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (ll x = 0; x <n; x++) {
                       ^
input/code.cpp:42:31: error: expected ']' before ')' token
    m[x1][y1][sum(x1, x, y1, y)) % C]++;
                               ^
input/code.cpp:42:31: error: expected ';' before ')' token
input/code.cpp:43:35: error: expected ']' before ')' token
    m2[x1][y + 1][sum(x1, x, y1, y)) % C]++;
                                   ^
input/code.cpp:43:35: error: expected ';' before ')' token
input/code.cpp:44:45: error: expected ']' before ')' token
    ans +=  m[x + 1][y + 1][sum(x1, x, y1, y)) % C];
                                             ^
input/code.cpp:44:45: error: expected ';' before ')' token
input/code.cpp:45:42...

Code

#include <bits/stdc++.h>
#define ll unsigned int//long long
#define INF 999999999
#define N (1<<17)
#define M 1000000007
#define C 250000

using namespace std;

ll ans = 0;
ll v[50][50];
ll m[50][50][250000];
ll m2[50][50][250000];
const inline ll sum (const ll x1, const ll x2, const ll y1, const ll y2) {
  ll s = v[y2][x2];
  if (x1) s -= v[y2][x1-1];
  if (y1) s -= v[y1-1][x2];
  if (x1 && y1) s += v[y1-1][x1-1];
  return s;
}

int main () {
  cin.sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin>>n;
  for (int y = 0; y < n; y++) {
    for (int x = 0; x <n; x++) {
      cin>>v[y][x];
      if (x) v[y][x] += v[y][x - 1];
    }
  }
  for(int y = 1; y < n; y++) {
    for (int x = 0; x < n; x++) {
     v[y][x] += v[y - 1][x]; 
    }
  }
  for (ll y = 0; y < n; y++) {
    for (ll x = 0; x <n; x++) {
      for (ll y1 = 0; y1 <= y; y1++) {
	for (ll x1 = 0; x1 <= x; x1++) {
	  m[x1][y1][sum(x1, x, y1, y)) % C]++;
	  m2[x1][y + 1][sum(x1, x, y1, y)) % C]++;
	  ans +=  m[x + 1][y + 1][sum(x1, x, y1, y)) % C];
	  ans += m2[x + 1][y1][sum(x1, x, y1, y)) % C];
	}
      }
    }
  }
  cout<<ans<<endl;
}