結果

問題 No.883 ぬりえ
ユーザー ikdikd
提出日時 2019-09-13 22:58:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 864 bytes
コンパイル時間 774 ms
コンパイル使用メモリ 78,792 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-17 15:04:43
合計ジャッジ時間 2,952 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 RE -
testcase_08 AC 2 ms
4,376 KB
testcase_09 RE -
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 16 ms
4,428 KB
testcase_16 AC 273 ms
4,380 KB
testcase_17 AC 84 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {

  int n, k;
  cin >> n >> k;

  auto m = (n + k - 1) / k; // m <= n
  m = max(m, (int)ceil(sqrt(n)));
  vector<vector<char>> a(m, vector<char>(m, '.'));
  rep(i, m) a[i][i] = '#';
  auto bk = m;
  rep(i, m) {
    rep(j, m) {
      if (a[i][j] == '#') continue;
      if (bk >= n) continue;
      int r_cnt = 0;
      rep(h, m) {
        if (a[h][j] == '#') r_cnt += 1;
      }
      int c_cnt = 0;
      rep(h, m) {
        if (a[i][h] == '#') c_cnt += 1;
      }
      if (r_cnt < k and c_cnt < k) {
        a[i][j] = '#';
        bk += 1;
      }
    }
  }
  cout << m << endl;
  rep(i, m) {
    rep(j, m) { cout << a[i][j]; }
    cout << endl;
  }
  assert(bk == n);

  return 0;
}
0