結果

問題 No.640 76本のトロンボーン
ユーザー startcppstartcpp
提出日時 2018-01-29 16:23:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,636 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 68,852 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 15:20:17
合計ジャッジ時間 1,512 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 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;
	cin >> n;
	s.resize(n);
	rep(i, n) cin >> s[i];
	
	int ans1 = getAns(s, ss);
	rotate(s, n);
	int ans2 = getAns(s, ss);
	cout << max(ans1, ans2) << endl;
	return 0;
}
0