結果

問題 No.883 ぬりえ
ユーザー 夜
提出日時 2020-12-08 18:50:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,848 bytes
コンパイル時間 1,045 ms
コンパイル使用メモリ 95,936 KB
実行使用メモリ 5,588 KB
最終ジャッジ日時 2023-10-17 22:39:23
合計ジャッジ時間 2,430 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
string s[1010];
int main() {
	int n, k;
	cin >> n >> k;
	if (n <= k * k) {
		for (int i = 1;; i++) {
			if (i * i >= n) {
				int co = 0;
				cout << i << endl;
				for (int j = 0; j < i; j++) {
					for (int k = 0; k < i; k++) {
						if (co < n) {
							co++;
							cout << '#';
						}
						else {
							cout << '.';
						}
					}
					cout << endl;
				}
				return 0;
			}
		}
	}
	int ans = (n + k * k - 1) / (k * k);
	ans *= k;
	for (int i = 0; i < ans; i++) {
		s[i] = "";
		for (int j = 0; j < ans; j++) {
			s[i] += '.';
		}
	}
	for (int i = 0; i < ans; i++) {
		s[i][i / k * k] = '#';
		s[i / k * k][i] = '#';
	}
	for (int i = 1; i < ans; i++) {
		for (int j = 1; j < ans; j++) {
			if (s[i - 1][j] == '#' && s[i][j - 1] == '#') {
				s[i][j] = '#';
			}
		}
	}
	int co = 0;
	for (int i = 0; i < ans; i++) {
		for (int j = 0; j < ans; j++) {
			if (s[i][j] == '#') {
				co++;
			}
		}
	}
	for (int i = ans - 1; i >= 0; i--) {
		for (int j = 0; j < ans - i; j++) {
			if (s[ans - 1 - j][i + j] == '#') {
				if (co > n) {
					s[ans - 1 - j][i + j] = '.';
					co--;
				}
			}
		}
	}
	for (int i = ans - 2; i >= 0; i--) {
		for (int j = 0; j <= i; j++) {
			if (s[i - j][j] == '#') {
				if (co > n) {
					s[i - j][j] = '.';
					co--;
				}
			}
		}
	}
	int m = -1;
	for (int i = 0; i < ans; i++) {
		for (int j = 0; j < ans; j++) {
			if (s[i][j] == '#') {
				if (m < i) {
					m = i;
				}
				if (m < j) {
					m = j;
				}
			}
		}
	}
	cout << m + 1 << endl;
	for (int i = 0; i <= m; i++) {
		cout << s[i].substr(0, m + 1) << endl;
	}
}
0