Submission #2064080


Source Code Expand

#include <iostream>
#include <string>
#include <vector>
#include <array>

using namespace std;

typedef struct Point {
  int x;
  int y;
} POINT;

class Solver {
private:
  const int w;
  const int h;
  vector< vector<int> > cells;
  vector<int> dxs;
  vector<int> dys;

public:
  Solver() : w(30), h(30) {
    cells.resize(h);

    // TODO 書き方を忘れた
    dxs.resize(4);
    dxs[0] = 0;
    dxs[1] = -1;
    dxs[2] = 0;
    dxs[3] = 1;
    dys.resize(4);
    dys[0] = -1;
    dys[1] = 0;
    dys[2] = 1;
    dys[3] = 0;
    // [(0, -1), (-1, 0), (0, 1), (1, 0)]
  }

  void input() {
    int s;
    for (int y = 0; y < h; y++) {
      for (int x = 0; x < w; x++) {
        cin >> s;
        cells[y].push_back(s);
      }
    }

    // check
    for (int y = 0; y < h; y++) {
      for (int x = 0; x < w; x++) {
        cout << cells[y][x] << " ";
      }
      cout << endl;
    }
  }

  void run() {
    array<int, 2> p = search_top();
    while ((p[0] >= 0 && p[1] >= 0)) {
      while (1) {
        int x = p[0];
        int y = p[1];
        cout << y+1 << " " << x+1 << endl;
        cells[y][x] = cells[y][x] - 1;

        array<int , 2> next{-1, -1};
        for (int i = 0; i < 4; i++) {
          int nx = x + dxs[i];
          int ny = y + dys[i];
          if (!check_border(nx, ny)) {
            continue;
          }
          if ((cells[y][x] == cells[ny][nx]) && (cells[ny][nx] > 0)) {
            next[0] = nx;
            next[1] = ny;
            break;
          }
        }
        if (next[0] >= 0 && next[1] >= 0) {
          p = next;
          continue;
        }
        break;
      }
      // 更新
      p = search_top();
    }
  }

  bool compare_around(int x, int y) {
    for (int i = 0; i < 4; i++) {
      int nx = x + dxs[i];
      int ny = y + dys[i];
      if (!check_border(nx, ny)) {
        continue;
      }
      if (cells[y][x] < cells[ny][nx]) {
        return false;
      }
    }
    return true;
  }

  array<int, 2> search_top() {
    array<int, 2> point;
    for (int y = 0; y < h; y++) {
      for (int x = 0; x < w; x++) {
        if (cells[y][x] <= 0) {
          continue;
        }
        if (compare_around(x, y)) {
          point[0] = x;
          point[1] = y;
          return point;
        }
      }
    }
    point[0] = -1;
    point[1] = -1;
    return point;
  }

  bool check_border(int x, int y) {
    if (x < 0 || x >= w || y < 0 || y >= h) {
      return false;
    }
    return true;
  }
};

int main() {
  Solver solver;
  solver.input();
  solver.run();

  return 0;
}

Submission Info

Submission Time
Task A - 高橋君の山崩しゲーム
User ksakiyama134
Language C++14 (Clang 3.8.0)
Score 0
Code Size 2691 Byte
Status WA
Exec Time 145 ms
Memory 512 KB

Judge Result

Set Name test_01 test_02 test_03 test_04 test_05 test_06 test_07 test_08 test_09 test_10
Score / Max Score 0 / 100000 0 / 100000 0 / 100000 0 / 100000 0 / 100000 0 / 100000 0 / 100000 0 / 100000 0 / 100000 0 / 100000
Status
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
WA × 1
Set Name Test Cases
test_01 subtask_01_01.txt
test_02 subtask_01_02.txt
test_03 subtask_01_03.txt
test_04 subtask_01_04.txt
test_05 subtask_01_05.txt
test_06 subtask_01_06.txt
test_07 subtask_01_07.txt
test_08 subtask_01_08.txt
test_09 subtask_01_09.txt
test_10 subtask_01_10.txt
Case Name Status Exec Time Memory
subtask_01_01.txt WA 133 ms 512 KB
subtask_01_02.txt WA 139 ms 512 KB
subtask_01_03.txt WA 135 ms 512 KB
subtask_01_04.txt WA 145 ms 512 KB
subtask_01_05.txt WA 134 ms 512 KB
subtask_01_06.txt WA 145 ms 512 KB
subtask_01_07.txt WA 139 ms 512 KB
subtask_01_08.txt WA 133 ms 512 KB
subtask_01_09.txt WA 139 ms 512 KB
subtask_01_10.txt WA 138 ms 512 KB