結果

問題 No.640 76本のトロンボーン
ユーザー startcppstartcpp
提出日時 2018-01-29 16:46:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,815 bytes
コンパイル時間 708 ms
コンパイル使用メモリ 68,688 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 23:00:32
合計ジャッジ時間 1,584 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

//n * n正方行列を90度右回転
void rotate(vector<string> &s, int n) {
	int i, j;
	vector<string> t;
	t.resize(n);
	rep(i, n) t[i].resize(n);
	rep(i, n) rep(j, n) t[j][n - 1 - i] = s[i][j];
	s = t;
}

//ブロックを置けるか?(範囲外参照はチェックしない実装)
bool canPut(vector<string> &s, int sy, int sx, int dy, int dx, int len) {
	int i;
	rep(i, len) {
		int y = sy + dy * i;
		int x = sx + dx * i;
		if (s[y][x] == '#') return false;
	}
	return true;
}

void put(vector<string> &s, int sy, int sx, int dy, int dx, int len) {
	int i;
	rep(i, len) {
		int y = sy + dy * i;
		int x = sx + dx * i;
		s[y][x] = '#';
	}
}

//列方向に1個以下おいた場合の答え (s…初期盤面, ss…操作用盤面)
int getAns(vector<string> &s, vector<string> &ss) {
	int sy, sx, y, x;
	int ret = 0, cnt;
	int n = s.size();
	
	rep(sx, n) {
		rep(sy, 2) {
			if (!canPut(s, sy, sx, 1, 0, n - 1)) continue;
			ss = s;
			put(ss, sy, sx, 1, 0, n - 1);
			
			cnt = 1;
			rep(y, n) {
				rep(x, 2) {
					if (canPut(ss, y, x, 0, 1, n - 1)) break;
				}
				if (x < 2) cnt++;
			}
			ret = max(cnt, ret);
		}
	}
	
	cnt = 0;
	rep(y, n) {
		rep(x, 2) {
			if (canPut(s, y, x, 0, 1, n - 1)) break;
		}
		if (x < 2) cnt++;
	}
	ret = max(cnt, ret);
	return ret;
}

int n;
vector<string> s, ss;

int main() {
	int i, j;
	cin >> n;
	s.resize(n);
	rep(i, n) cin >> s[i];
	
	int ans = 0;
	bool cornerCase = true;
	rep(i, n) rep(j, n) if ((i == 0 || j == 0 || i == n - 1 || j == n - 1) && s[i][j] == '#') cornerCase = false;
	if (cornerCase) ans = 4;
	
	ans = max(ans, getAns(s, ss));
	rotate(s, n);
	ans = max(ans, getAns(s, ss));
	cout << ans << endl;
	return 0;
}
0