結果

問題 No.3734 No Flat Notes
コンテスト
ユーザー tnakao0123
提出日時 2026-09-29 18:09:46
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,971 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 225 ms
コンパイル使用メモリ 58,044 KB
実行使用メモリ 9,900 KB
最終ジャッジ日時 2026-09-29 18:09:55
合計ジャッジ時間 4,808 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
部分点 20 % AC * 28
満点 80 % AC * 53 WA * 7
合計 3.5 * 20% = 70 点
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3734.cc:  No.3734 No Flat Notes - yukicoder
 */

#include<cstdio>
#include<cassert>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_H = 500;
const int MAX_W = 500;
const int MAX_HW = MAX_H * MAX_W;

/* typedef */

/* global variables */

int ps[MAX_HW], as[MAX_HW];

/* subroutines */

void forward(int w, int &y, int &x, int &dx) {
  x += dx;
  if (x >= w) x = w - 1, dx = -1, y++;
  else if (x < 0) x = 0, dx = 1, y++;
}

bool check(int h, int w, int m) {
  int dxs[] = {1, 0, -1, 0}, dys[] = {0, -1, 0, 1};
  int yc = 0, tc = 0;
  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++) {
      int nbc = 0, lc = 0, gc = 0;
      for (int di = 0; di < 4; di++) {
	int vy = y + dys[di], vx = x + dxs[di];
	if (vy >= 0 && vy < h && vx >= 0 && vx < w) {
	  nbc++;
	  if (as[vy * w + vx] < as[y * w + x]) lc++;
	  else gc++;
	}
      }
      if (nbc == lc) yc++;
      else if (nbc == gc) tc++;
    }
  printf(" check(%d,%d,%d) = %d,%d\n", h, w, m, yc, tc);
  return yc == m && tc == m;
}

/* main */

int main() {
  int h, w, m;
  scanf("%d%d%d", &h, &w, &m);
  int hw = h * w;
  int t = hw - m * 2;
  
  if (m <= 0 || m * 2 > hw || ((hw & 1) && t <= 1)) {
    puts("-1"); return 0;
  }

  for (int i = 0, y = 0, x = 0, dx = 1; i < hw; i++) {
    ps[i] = y * w + x;
    forward(w, y, x, dx);
  }
  
  int mn = 1, mx = hw, k = 0;
  if (h > 1 && w > 1 && (hw & 1) && t <= w * 2 - w) {
    for (int i = 0; i < m; i++) {
      as[ps[k++]] = mn++;
      as[ps[k++]] = mx--;
    }
    as[ps[k++]] = mn + 1;
    as[ps[k++]] = mn;
    mn += 2;
    while (k < hw)
      as[ps[k++]] = mn++;
  }
  else {
    for (int i = 1; i < m; i++) {
      as[ps[k++]] = mn++;
      as[ps[k++]] = mx--;
    }
    while (k < hw)
      as[ps[k++]] = mn++;
  }
  
  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      printf("%d%c", as[y * w + x], (x + 1 < w) ? ' ' : '\n');
  
  //assert(check(h, w, m));
  
  return 0;
}
0