Submission #3157688


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;
bool a[510][510];

typedef tuple<int, int, int, int> X;
vector<X> V;
int odd[510];

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)
{
  // swap(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 >> x;
      a[i][j] = (x % 2 == 1);
    }
  }
  fill(odd, odd + 510, -1);
  for (auto i = 0; i < H; i++)
  {
    int y = -1;
    int cnt = 0;
    for (auto j = 0; j < W; j++)
    {
      if (a[i][j])
      {
        // cerr << "(" << i << ", " << j << ")" << endl;
        if (cnt % 2 == 0)
        {
          y = j;
        }
        else
        {
          int z = j;
          // cerr << "y = " << y << ", z = " << z << endl;
          for (auto k = y; k < z; k++)
          {
            make_swap(i, k, i, k + 1);
          }
        }
        cnt++;
      }
    }
    if (cnt % 2 == 1)
    {
      odd[i] = y;
      for (auto k = y; k < W - 1; k++)
      {
        make_swap(i, k, i, k + 1);
      }
    }
  }
  int x = -1;
  int cnt = 0;
  for (auto i = 0; i < H; i++)
  {
    if (odd[i] >= 0)
    {
      if (cnt % 2 == 0)
      {
        x = i;
      }
      else
      {
        int z = i;
        for (auto k = x; k < z; k++)
        {
          make_swap(k, W - 1, k + 1, W - 1);
        }
      }
      cnt++;
    }
  }
  flush();
}

Submission Info

Submission Time
Task D - Make Them Even
User kazunetakahashi
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2878 Byte
Status AC
Exec Time 284 ms
Memory 4464 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 512 KB
hand_5 AC 270 ms 4464 KB
hand_6 AC 42 ms 512 KB
max_1 AC 270 ms 4464 KB
max_10 AC 281 ms 4464 KB
max_2 AC 274 ms 4464 KB
max_3 AC 276 ms 4464 KB
max_4 AC 272 ms 4464 KB
max_5 AC 272 ms 4464 KB
max_6 AC 273 ms 4464 KB
max_7 AC 284 ms 4464 KB
max_8 AC 274 ms 4464 KB
max_9 AC 275 ms 4464 KB
random_1 AC 3 ms 256 KB
random_10 AC 36 ms 892 KB
random_2 AC 58 ms 1400 KB
random_3 AC 85 ms 1656 KB
random_4 AC 28 ms 768 KB
random_5 AC 45 ms 1144 KB
random_6 AC 109 ms 2036 KB
random_7 AC 76 ms 1528 KB
random_8 AC 97 ms 1908 KB
random_9 AC 155 ms 2676 KB
sample_01 AC 1 ms 256 KB
sample_02 AC 1 ms 256 KB
sample_03 AC 1 ms 256 KB