結果

問題 No.1988 Divisor Tiling
ユーザー tnakao0123tnakao0123
提出日時 2022-06-25 15:20:18
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,163 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 41,964 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-09 07:09:20
合計ジャッジ時間 3,291 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1988.cc:  No.1988 Divisor Tiling - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_M = 10000;

/* typedef */

/* global variables */

int as[MAX_M];

/* subroutines */

/* main */

int main() {
  // perfect number = 2^(k-1)*(2^k-1)
  //    6: k=2
  //   28: k=3
  //  496: k=5
  // 8128: k=7

  int n, h;
  scanf("%d%d", &n, &h);
  int w = n / h;

  int k = (n == 6) ? 2 : (n == 28) ? 3 : (n == 496) ? 5 : 7;
  int f = (1 << k) - 1;
  //printf("k=%d, f=%d\n", k, f);

  int m = 0;
  for (int j = 0, ej = 1; j < k; j++, ej *= 2) {
    int a = ej;
    for (int l = 0; l < a; l++) as[m++] = a;
  }
  for (int j = 0, ej = 1; j < k - 1; j++, ej *= 2) {
    int a = ej * f;
    for (int l = 0; l < a; l++) as[m++] = a;
  }
  //for (int i = 0; i < n; i++) printf("%d ", as[i]); putchar('\n');

  if (w % f == 0)
    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');
  else
    for (int y = 0; y < h; y++)
      for (int x = 0; x < w; x++)
	printf("%d%c", as[x * h + y], (x + 1 < w) ? ' ' : '\n');

  return 0;
}
0