Submission #1108337

# Submission time Handle Problem Language Result Execution time Memory
1108337 2024-11-03T21:00:40 Z Ludissey Mosaic (IOI24_mosaic) C++17
0 / 100
1000 ms 1652776 KB
#include "mosaic.h"

#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
 
using namespace std;

int q,n;
vector<vector<int>> left,top; 

vector<int> dia;
// X cest le top
// Y cest la gauche

// [le x][le y]

int todia(int x, int y){
  return (n-x-1)+y;
}

std::vector<long long> mosaic(std::vector<signed> X, std::vector<signed> Y, std::vector<signed> T, std::vector<signed> B,std::vector<signed> L, std::vector<signed> R) {
  q = sz(T); n=sz(Y);
  left.resize(2,vector<int>(n,0));
  top.resize(n,vector<int>(2,0));
  dia.resize(n+n-1,0);
  for (int i = 0; i < n; i++)
  {
    left[0][i]=Y[i];
    top[i][0]=X[i];
  }
  for (int i = 1; i < n&&n>1; i++)
  {
    top[i][1]=(top[i-1][1]==0&&top[i][0]==0);
    left[1][i]=(left[1][i-1]==0&&left[0][i]==0);
    dia[todia(i,1)]=top[i][1];
    dia[todia(1,i)]=left[1][i];

  }

  vector<vector<int>> fullgrid(n,vector<int>(n,0));
  vector<vector<int>> prefix(n,vector<int>(n,0));
  for (int i = 0; i < n; i++){
    for (int j = 0; j < min(n,2LL); j++)
    {
      fullgrid[i][j]=top[i][j];
      fullgrid[j][i]=left[j][i];
    }
  }
  for (int i = 2; i < n; i++){
    for (int j = 2; j < n; j++)
    {
      fullgrid[i][j]=dia[todia(i,j)];
      fullgrid[j][i]=dia[todia(j,i)];
    }
  }
  for (int i = 0; i < n; i++){
    for (int j = 0; j < n; j++)
    {
      prefix[i][j]=fullgrid[i][j];
      if(i>0) prefix[i][j]+=prefix[i-1][j];
      if(j>0) prefix[i][j]+=prefix[i][j-1];
      if(i>0&&j>0) prefix[i][j]-=prefix[i-1][j-1];
    }
  }
  std::vector<long long> C(q, 0);
  for (int i = 0; i < q; i++)
  {
    int l=L[i],r=R[i],t=T[i],b=B[i];
    int sm=prefix[r][b];
    if(l>0) sm-=prefix[l-1][b];
    if(t>0) sm-=prefix[r][t-1];
    if(l>0&&t>0) sm+=prefix[l-1][t-1];
    C[i]=sm;
  }
  return C;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Incorrect 1 ms 336 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Incorrect 1 ms 336 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1189 ms 1621564 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Incorrect 1 ms 336 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 9800 KB Output is correct
2 Execution timed out 1199 ms 1652776 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1180 ms 1646928 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1189 ms 1621564 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Incorrect 1 ms 336 KB Output isn't correct
7 Halted 0 ms 0 KB -