Submission #1138957


Source Code Expand

#include <iostream>
#include <vector>
#include <random>

using namespace std;
// template for creating 2d vector
template<typename T>
vector<vector<T>> make_2d_vector(size_t rows, size_t cols, T init)
{ return vector< vector<T> >(rows, vector<T>(cols, init)); }


typedef vector< vector<int> > two_d_vector;

random_device rnd;


#define debug(x) cout << #x << "==" << x << endl;

const int inf = 100000000;

typedef long long ll;

#define N 30
auto A = make_2d_vector(30, 30, 0);

//移動4方向のベクトル
int di[4] = {1, 0, -1, 0};
int dj[4] = {0, 1,  0, -1};

typedef pair<int,int> P;

bool in_bound(P p) {
  int i = p.first; int j = p.second;
  return (i < N) && (0 <= i) && (j < N) && (0 <= j);
}

int get_A(P p) {
  return A[p.first][p.second];
}

void print_A() {
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      cout << A[i][j] << " ";
    } cout << "\n";
  } cout << "\n";
}

P next_index(P p) {
  int i = p.first; int j = p.second;
  if( i % 2 == 0 ) {
    if( j+1 < N ) return P(i, j+1);
    else           return P(i+1, j);
  } else {
    if( j-1 > -1 ) return P(i, j-1);
    else           return P(i+1, j);
  }
}

P prev_index(P p) {
  int i = p.first; int j = p.second;
  if( i % 2 == 0 ) {
    if( j-1 > -1 ) return P(i, j-1);
    else           return P(i-1, j);
  } else {
    if( j+1 < N )  return P(i, j+1);
    else           return P(i-1, j);
  }
}



void put(P p) {
  int i = p.first; int j = p.second;
  if( A[i][j] == 0 ) { return; }
  A[i][j] -= 1;
  cout << i+1 << " " << j+1 << "\n";
  int num = A[i][j];

  P np = next_index(p);
  if( not in_bound(np) ) {
    return;
  } else if( A[p.first][p.second] == num ) {
    put(np);
  } else {
    return;
  }

}

P max_index() {
  P max_index;
  int max_n = 0;
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      int n = A[i][j];
      if(max_n < n) {
        max_index = P(i,j);  max_n = n;
      } else if ( (max_n == n) && (rnd() % 2 == 0) )  max_index = P(i,j);
    }
  }
  return max_index;
}


int main() {
  ios::sync_with_stdio(false);
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }

  P p = P(N-1,N-1);
  while( in_bound(p) ) {
    P pp = prev_index(p);
    if( not in_bound(pp) ) break;
    if( get_A(pp) <= get_A(p) ) {
      put(p);
    } else {
      p = pp;
    }
  }

  p = P(0, 0);
  while( get_A(p) > 0 ) {
    put(p);
  }

  // while(true) {
  //   P mxi = max_index();
  //   int i = mxi.first; int j = mxi.second;
  //   if( A[i][j] == 0) { break; }
  //   put( P(i, j) );
  // }

  // P p = P(2,2);
  // while( in_bound(p) ) {
  //   cout << p.first << ", " << p.second << "\n";
  //   p = prev_index( p );
  // }

  // print_A();

  return 0;
}

Submission Info

Submission Time
Task A - 高橋君の山崩しゲーム
User sadtomato
Language C++14 (Clang 3.8.0)
Score 0
Code Size 2881 Byte
Status WA
Exec Time 24 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 22 ms 512 KB
subtask_01_02.txt WA 23 ms 512 KB
subtask_01_03.txt WA 22 ms 512 KB
subtask_01_04.txt WA 24 ms 512 KB
subtask_01_05.txt WA 23 ms 512 KB
subtask_01_06.txt WA 22 ms 512 KB
subtask_01_07.txt WA 23 ms 512 KB
subtask_01_08.txt WA 22 ms 512 KB
subtask_01_09.txt WA 23 ms 512 KB
subtask_01_10.txt WA 23 ms 512 KB