結果

問題 No.5002 stick xor
ユーザー square1001square1001
提出日時 2018-05-26 10:52:16
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,878 bytes
コンパイル時間 2,244 ms
実行使用メモリ 1,576 KB
スコア 0
最終ジャッジ日時 2018-05-26 10:52:20
ジャッジサーバーID
(参考情報)
judge10 /
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int seed = 123456789;
int rand_gen() {
	seed ^= seed << 13;
	seed ^= seed >> 17;
	seed ^= seed << 5;
	return seed;
}
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> L(K);
	for (int i = 0; i < K; i++) cin >> L[i];
	vector<vector<int> > v(N, vector<int>(N));
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		for (int j = 0; j < N; j++) {
			v[i][j] = s[j] - '0';
		}
	}
	vector<vector<int> > x = v;
	vector<int> vx(K), vy(K);
	int score = 0;
	for (int i = 0; i < K; i++) {
		int px = -1, py = -1, cur = -1;
		for (int j = 0; j < N; j++) {
			for (int k = 0; k <= N - L[i]; k++) {
				int sum = 0;
				for (int l = k; l < k + L[i]; l++) sum += x[j][l];
				if (sum > cur) {
					cur = sum, px = j, py = k;
				}
			}
		}
		vx[i] = px;
		vy[i] = py;
		for (int j = py; j < py + L[i]; j++) x[px][j] ^= 1;
		score += cur * 2 - L[i];
	}
	while (true) {
		int iniscore = score;
		for (int i = 0; i < K; i++) {
			int choose = 0, cur = 0;
			for (int j = -N + 1; j <= N - 1; j++) {
				if (j == 0) continue;
				int ty = vy[i] + j;
				if (0 <= ty && ty <= N - L[i]) {
					int delta = 0;
					for (int k = ty + L[i]; k < vy[i] + L[i]; k++) delta += (x[vx[i]][k] == 1 ? 1 : -1);
					for (int k = ty; k < vy[i]; k++) delta += (x[vx[i]][k] == 1 ? 1 : -1);
					if (delta > cur) {
						cur = delta;
						choose = j;
					}
				}
			}
			if (choose != 0) {
				int ty = vy[i] + choose;
				for (int k = ty + L[i]; k < vy[i] + L[i]; k++) score += (x[vx[i]][k] == 1 ? 1 : -1), x[vx[i]][k] ^= 1;
				for (int k = ty; k < vy[i]; k++) score += (x[vx[i]][k] == 1 ? 1 : -1), x[vx[i]][k] ^= 1;
				vy[i] = ty;
			}
		}
		if (score == iniscore) break;
	}
	for (int i = 0; i < N; i++) cout << vx[i] + 1 << ' ' << vy[i] + 1 << ' ' << vx[i] + 1 << ' ' << vy[i] + L[i] << endl;
	return 0;
}
0