結果
| 問題 | No.3734 No Flat Notes |
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2026-09-29 18:22:33 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 1,960 bytes |
| 記録 | |
| コンパイル時間 | 233 ms |
| コンパイル使用メモリ | 57,964 KB |
| 実行使用メモリ | 9,904 KB |
| 最終ジャッジ日時 | 2026-09-29 18:22:41 |
| 合計ジャッジ時間 | 4,916 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| 部分点 | 20 % | AC * 28 |
| 満点 | 80 % | AC * 58 WA * 2 |
| 合計 | 3.5 * 20% = 70 点 |
ソースコード
/* -*- 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 - 3) {
for (int i = 0, a = m + 1; i < t; i++)
as[ps[k++]] = a++;
swap(as[ps[t - 2]], as[ps[t - 1]]);
while (k < hw) {
as[ps[k++]] = mn++;
as[ps[k++]] = mx--;
}
}
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;
}
tnakao0123