Submission #1246334

#TimeUsernameProblemLanguageResultExecution timeMemory
1246334CyberCowMosaic (IOI24_mosaic)C++20
22 / 100
207 ms204076 KiB
#include "mosaic.h"
#include <bits/stdc++.h>
using namespace std;

int a[5005][5005];
int pref[5005][5005];

int gum(int x, int x1, int y, int y1)
{
  int arj = pref[x1][y1];
  if(x)arj -= pref[x - 1][y1];
  if(y)arj-=pref[x1][y - 1];
  if(x && y)arj += pref[x - 1][y - 1];
  return arj;
}

vector<long long> mosaic(vector<int> X, vector<int> Y,
                              vector<int> T, vector<int> B,
                              vector<int> L, vector<int> R) {
  int Q = (int)T.size();
  vector<long long> C(Q, 0);
  pref[0][0] = X[0];
  a[0][0] = X[0];
  for (int i = 1; i < X.size(); i++)
  {
    a[0][i] = X[i];
    pref[0][i] = pref[0][i - 1] + a[0][i];
  }
  for (int i = 1; i < Y.size(); i++)
  {
    a[i][0] = Y[i];
    pref[i][0] = pref[i - 1][0] + a[i][0];
  }
  int n = X.size();
  for (int i = 1; i < n; i++)
  {
    for (int j = 1; j < n; j++)
    {
      if(a[i - 1][j] == 0 && a[i][j - 1] == 0)
      {
        a[i][j] = 1;
        if(a[i - 1][j - 1] == 0 && i > 2 && j > 2)
        {
          throw;
        }
      }
      pref[i][j] = pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + a[i][j];
    }
  }
  for (int i = 0; i < Q; i++)
  {
    C[i] = gum(T[i], B[i], L[i], R[i]);
  }
  return C;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...