Submission #5539298


Source Code Expand

#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)

int H, W, K;
vector<vector<int>> cpt;
int current_piece_no = 10;

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

void make_piece(int y, int x, int selected_cpt) {
  if (selected_cpt >= K)
    return;

  cpt[y][x] = current_piece_no;

  int nx, ny;
  int mx, my, maxi = -1;
  rep(i, 4) {
    nx = x + dx[i];
    ny = y + dy[i];
    if (nx < 0 || nx >= W || ny < 0 || ny >= H)
      continue;
    if (cpt[ny][nx] >= 10)
      continue;
    if (cpt[ny][nx] > maxi) {
      mx = nx;
      my = ny;
    }
  }

  make_piece(my, mx, selected_cpt + 1);
}

void dump_piece(int y, int x, int piece_no) {
  cout << y + 1 << " " << x + 1 << endl;

  cpt[y][x] = -1;

  int nx, ny;
  rep(i, 4) {
    nx = x + dx[i];
    ny = y + dy[i];
    if (nx < 0 || nx >= W || ny < 0 || ny >= H)
      continue;
    if (cpt[ny][nx] != piece_no)
      continue;
    dump_piece(ny, nx, piece_no);
  }
}

int main(void) {
  cin >> H >> W >> K;
  cpt.resize(H);

  string s;
  rep(i, H) {
    cpt[i].resize(W);
    cin >> s;
    rep(j, W) cpt[i][j] = s[j] - '0';
  }
  rep(i, H) rep(j, W) {
    if (cpt[i][j] >= 10) continue;
    make_piece(i, j, 0);
    current_piece_no++;
  }
  cout << current_piece_no - 10 << endl;
  rep(i, H) rep(j, W) {
    if (cpt[i][j] < 10) continue;
    dump_piece(i, j, cpt[i][j]);
  }
}

Submission Info

Submission Time
Task A - Multiple Pieces
User d2verb
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1489 Byte
Status WA
Exec Time 6 ms
Memory 256 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 / 1343058 0 / 1343058 0 / 1343058 0 / 1343058 0 / 1343058 0 / 1343058 0 / 1343058 0 / 1343058 0 / 1343058 0 / 1343058
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 5 ms 256 KB
subtask_01_02.txt WA 5 ms 256 KB
subtask_01_03.txt WA 5 ms 256 KB
subtask_01_04.txt WA 6 ms 256 KB
subtask_01_05.txt WA 5 ms 256 KB
subtask_01_06.txt WA 6 ms 256 KB
subtask_01_07.txt WA 6 ms 256 KB
subtask_01_08.txt WA 5 ms 256 KB
subtask_01_09.txt WA 5 ms 256 KB
subtask_01_10.txt WA 5 ms 256 KB