답안 #667907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667907 2022-12-02T10:16:24 Z 600Mihnea 보물 찾기 (CEOI13_treasure2) C++17
73 / 100
2 ms 468 KB
#include "treasure.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 100 + 7;
int s[4][N][N];
bool deja = 0;
bool ok;
int n;


int get(int type, int r, int c)
{
  if (type == 0)
  {
    if (r <= 0 || c <= 0)
    {
      return 0;
    }
    ok &= (s[type][r][c] != -1);
    return s[type][r][c];
  }
  if (type == 1)
  {
    if (r <= 0 || c > n)
    {
      return 0;
    }
    ok &= (s[type][r][c] != -1);
    return s[type][r][c];
  }
  if (type == 2)
  {
    if (r > n || c <= 0)
    {
      return 0;
    }
    ok &= (s[type][r][c] != -1);
    return s[type][r][c];
  }
  if (type == 3)
  {
    if (r > n || c > n)
    {
      return 0;
    }
    ok &= (s[type][r][c] != -1);
    return s[type][r][c];
  }

  assert(0);
}

int what(int r, int c)
{
  ok = 1;
  int sm;
  sm = get(0, r, c) - get(0, r - 1, c) - get(0, r, c - 1) + get(0, r - 1, c - 1);

  if (ok)
  {
    return sm;
  }

  ok = 1;
  sm = get(1, r, c) - get(1, r - 1, c) - get(1, r, c + 1) + get(1, r - 1, c + 1);

  if (ok)
  {
    return sm;
  }

  ok = 1;
  sm = get(2, r, c) - get(2, r + 1, c) - get(2, r, c - 1) + get(2, r + 1, c - 1);

  if (ok)
  {
    return sm;
  }

  ok = 1;
  sm = get(3, r, c) - get(3, r + 1, c) - get(3, r, c + 1) + get(3, r + 1, c + 1);

  if (ok)
  {
    return sm;
  }

  cout << "bad " << r << " " << c << "\n";

  return 0;
 /// assert(0);
}

void request(int type, int i, int j)
{
  if (type == 0)
  {
    if (s[type][i][j] == -1)
    {
      s[type][i][j] = countTreasure(1, 1, i, j);
    }
    return;
  }
  if (type == 1)
  {
    if (s[type][i][j] == -1)
    {
      s[type][i][j] = countTreasure(1, j, i, n);
    }
    return;
  }
  if (type == 2)
  {
    if (s[type][i][j] == -1)
    {
      s[type][i][j] = countTreasure(i, 1, n, j);
    }
    return;
  }
  if (type == 3)
  {
    if (s[type][i][j] == -1)
    {
      s[type][i][j] = countTreasure(i, j, n, n);
    }
    return;
  }
  assert(0);
}

void findTreasure(int nn)
{
  n = nn;
  for (int k = 0; k < 4; k++)
  {
    for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < N; j++)
      {
        s[k][i][j] = -1;
      }
    }
  }
  int stop = (n + 1) / 2;
  int start = (n - 1) / 2;
  /// compute 3
  for (int i = 1; i <= stop; i++)
  {
    for (int j = 1; j <= stop; j++)
    {
      request(3, i, j);
    }
  }
  for (int j = 1; j <= stop; j++)
  {
    s[1][n][j] = s[3][1][j];
  }
  for (int i = 1; i <= stop; i++)
  {
    s[2][i][n] = s[3][i][1];
  }

  /// compute 2
  for (int i = 1; i <= stop; i++)
  {
    for (int j = start; j <= n; j++)
    {
      request(2, i, j);
    }
  }

  /// compute 1
  for (int i = start; i <= n; i++)
  {
    for (int j = 1; j <= stop; j++)
    {
      request(1, i, j);
    }
  }
  for (int i = start; i <= n; i++)
  {
    s[0][i][n] = s[1][i][1];
  }

  /// compute 0
  for (int i = start; i <= n; i++)
  {
    for (int j = start; j <= n; j++)
    {
      request(0, i, j);
    }
  }

  for (int i = 1; i <= n; i++)
  {
    for (int j = 1; j <= n; j++)
    {
      if (what(i, j))
      {
        Report(i, j);
      }
    }
  }
}
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 468 KB Output is partially correct - N = 5, K = 528, score = 1
2 Partially correct 0 ms 468 KB Output is partially correct - N = 10, K = 6196, score = 8
3 Partially correct 1 ms 468 KB Output is partially correct - N = 15, K = 27428, score = 8
4 Partially correct 1 ms 468 KB Output is partially correct - N = 16, K = 35401, score = 8
5 Partially correct 1 ms 468 KB Output is partially correct - N = 55, K = 4240278, score = 8
6 Partially correct 1 ms 468 KB Output is partially correct - N = 66, K = 8714476, score = 8
7 Partially correct 1 ms 468 KB Output is partially correct - N = 77, K = 16022994, score = 8
8 Partially correct 1 ms 468 KB Output is partially correct - N = 88, K = 27205069, score = 8
9 Partially correct 1 ms 468 KB Output is partially correct - N = 99, K = 43386275, score = 8
10 Partially correct 2 ms 468 KB Output is partially correct - N = 100, K = 45165451, score = 8