Submission #3168503


Source Code Expand

/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-9-8 21:12:40
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int H, W;
int a[510][510];

typedef tuple<int, int, int, int> X;
vector<X> V;

void flush()
{
  int N = (int)V.size();
  cout << N << endl;
  for (auto i = 0; i < N; i++)
  {
    X x = V[i];
    cout << get<0>(x) + 1 << " " << get<1>(x) + 1 << " " << get<2>(x) + 1 << " " << get<3>(x) + 1 << endl;
  }
}

void make_swap(int x, int y, int z, int w)
{
  a[x][y]--;
  a[z][w]++;
  V.push_back(X(x, y, z, w));
}

int main()
{
  cin >> H >> W;
  for (auto i = 0; i < H; i++)
  {
    for (auto j = 0; j < W; j++)
    {
      int x;
      cin >> a[i][j];
    }
  }
  for (auto i = 0; i < H - 1; i++)
  {
    for (auto j = 0; j < W; j++)
    {
      if (a[i][j] % 2 == 1)
      {
        make_swap(i, j, i + 1, j);
      }
    }
  }
  for (auto j = 0; j < W - 1; j++)
  {
    if (a[H - 1][j] % 2 == 1)
    {
      make_swap(H - 1, j, H - 1, j + 1);
    }
  }
  flush();
}

Submission Info

Submission Time
Task D - Make Them Even
User kazunetakahashi
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2100 Byte
Status AC
Exec Time 278 ms
Memory 5232 KB

Judge Result

Set Name All Sample
Score / Max Score 400 / 400 0 / 0
Status
AC × 29
AC × 3
Set Name Test Cases
All hand_1, hand_2, hand_3, hand_4, hand_5, hand_6, max_1, max_10, max_2, max_3, max_4, max_5, max_6, max_7, max_8, max_9, random_1, random_10, random_2, random_3, random_4, random_5, random_6, random_7, random_8, random_9, sample_01, sample_02, sample_03
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
hand_1 AC 1 ms 256 KB
hand_2 AC 1 ms 256 KB
hand_3 AC 2 ms 256 KB
hand_4 AC 2 ms 1280 KB
hand_5 AC 272 ms 5232 KB
hand_6 AC 42 ms 1280 KB
max_1 AC 269 ms 5232 KB
max_10 AC 270 ms 5232 KB
max_2 AC 278 ms 5232 KB
max_3 AC 268 ms 5232 KB
max_4 AC 270 ms 5232 KB
max_5 AC 270 ms 5104 KB
max_6 AC 274 ms 5232 KB
max_7 AC 271 ms 5232 KB
max_8 AC 273 ms 5232 KB
max_9 AC 274 ms 5104 KB
random_1 AC 3 ms 384 KB
random_10 AC 35 ms 1148 KB
random_2 AC 57 ms 2040 KB
random_3 AC 83 ms 2292 KB
random_4 AC 27 ms 1020 KB
random_5 AC 45 ms 1528 KB
random_6 AC 105 ms 2676 KB
random_7 AC 76 ms 2040 KB
random_8 AC 97 ms 2292 KB
random_9 AC 148 ms 3316 KB
sample_01 AC 1 ms 256 KB
sample_02 AC 1 ms 256 KB
sample_03 AC 1 ms 256 KB