結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー 👑 emthrmemthrm
提出日時 2021-02-19 22:05:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 3,153 ms
コード長 2,511 bytes
コンパイル時間 3,933 ms
コンパイル使用メモリ 204,276 KB
実行使用メモリ 4,956 KB
最終ジャッジ日時 2023-10-15 01:49:29
合計ジャッジ時間 28,674 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 17 ms
4,796 KB
testcase_07 AC 3 ms
4,484 KB
testcase_08 AC 18 ms
4,816 KB
testcase_09 AC 17 ms
4,384 KB
testcase_10 AC 3 ms
4,372 KB
testcase_11 AC 17 ms
4,828 KB
testcase_12 AC 3 ms
4,356 KB
testcase_13 AC 17 ms
4,788 KB
testcase_14 AC 18 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 18 ms
4,956 KB
testcase_17 AC 18 ms
4,352 KB
testcase_18 AC 17 ms
4,352 KB
testcase_19 AC 18 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 17 ms
4,844 KB
testcase_22 AC 17 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 17 ms
4,884 KB
testcase_25 AC 3 ms
4,352 KB
testcase_26 AC 17 ms
4,956 KB
testcase_27 AC 17 ms
4,388 KB
testcase_28 AC 2 ms
4,372 KB
testcase_29 AC 17 ms
4,832 KB
testcase_30 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int w, h, x; cin >> w >> h >> x;
  vector m(h, vector(w, 0));
  if (x <= 9) {
    vector<int> r, c;
    if (h % 3 == 0) {
      for (int i = 1; i < h; i += 3) r.emplace_back(i);
    } else if (h % 3 == 1) {
      r.emplace_back(0);
      for (int i = 3; i < h; i += 3) r.emplace_back(i);
      r.emplace_back(h - 1);
    } else {
      for (int i = 0; i < h; i += 3) r.emplace_back(i);
    }
    if (w % 3 == 0) {
      for (int j = 1; j < w; j += 3) c.emplace_back(j);
    } else if (w % 3 == 1) {
      c.emplace_back(0);
      for (int j = 3; j < w; j += 3) c.emplace_back(j);
      c.emplace_back(w - 1);
    } else {
      for (int j = 0; j < w; j += 3) c.emplace_back(j);
    }
    for (int i : r) for (int j : c) m[i][j] = x;
  } else if (x <= 18) {
    if (h % 3 == 2) {
      for (int j = (w % 3 == 0 ? 1 : 0); j < w; j += 3) for (int i = 0; i + 1 < h; i += 3) {
        m[i][j] = 9;
        m[i + 1][j] = x - 9;
      }
    } else if (w % 3 == 2) {
      for (int i = (h % 3 == 0 ? 1 : 0); i < h; i += 3) for (int j = 0; j + 1 < w; j += 3) {
        m[i][j] = 9;
        m[i][j + 1] = x - 9;
      }
    } else {
      cout << "-1\n";
      return 0;
    }
  } else if (x <= 36) {
    if (h % 3 != 2 || w % 3 != 2) {
      cout << "-1\n";
      return 0;
    }
    for (int i = 0; i + 1 < h; i += 3) for (int j = 0; j + 1 < w; j += 3) {
      m[i][j] = m[i][j + 1] = 9;
      m[i + 1][j] = min(x - 18, 9);
      m[i + 1][j + 1] = x - (m[i + 1][j] + 18);
    }
  } else {
    cout << "-1\n";
    return 0;
  }
  REP(i, h) {
    REP(j, w) cout << m[i][j];
    cout << '\n';
  }
  return 0;
}
0