結果

問題 No.5002 stick xor
ユーザー square1001square1001
提出日時 2018-05-26 11:01:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 1,000 ms
コード長 1,301 bytes
コンパイル時間 3,445 ms
実行使用メモリ 1,576 KB
スコア 37,287
最終ジャッジ日時 2018-05-26 11:01:42
ジャッジサーバーID
(参考情報)
judge7 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
1,576 KB
testcase_01 AC 33 ms
1,572 KB
testcase_02 AC 50 ms
1,572 KB
testcase_03 AC 51 ms
1,572 KB
testcase_04 AC 33 ms
1,572 KB
testcase_05 AC 44 ms
1,576 KB
testcase_06 AC 43 ms
1,572 KB
testcase_07 AC 62 ms
1,576 KB
testcase_08 AC 46 ms
1,572 KB
testcase_09 AC 63 ms
1,576 KB
testcase_10 AC 47 ms
1,572 KB
testcase_11 AC 45 ms
1,572 KB
testcase_12 AC 65 ms
1,572 KB
testcase_13 AC 43 ms
1,572 KB
testcase_14 AC 61 ms
1,572 KB
testcase_15 AC 56 ms
1,576 KB
testcase_16 AC 39 ms
1,572 KB
testcase_17 AC 47 ms
1,572 KB
testcase_18 AC 45 ms
1,576 KB
testcase_19 AC 72 ms
1,576 KB
testcase_20 AC 39 ms
1,572 KB
testcase_21 AC 61 ms
1,572 KB
testcase_22 AC 42 ms
1,572 KB
testcase_23 AC 37 ms
1,572 KB
testcase_24 AC 41 ms
1,576 KB
testcase_25 AC 50 ms
1,576 KB
testcase_26 AC 41 ms
1,576 KB
testcase_27 AC 70 ms
1,572 KB
testcase_28 AC 63 ms
1,572 KB
testcase_29 AC 61 ms
1,576 KB
testcase_30 AC 62 ms
1,572 KB
testcase_31 AC 25 ms
1,576 KB
権限があれば一括ダウンロードができます

ソースコード

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, -1), vy(K, -1);
	int score = 0;
	while (true) {
		int iniscore = score;
		for (int i = 0; i < K; i++) {
			if (vx[i] != -1) {
				for (int j = vy[i]; j < vy[i] + L[i]; j++) score += (x[vx[i]][j] == 1 ? 1 : -1), x[vx[i]][j] ^= 1;
			}
			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];
		}
		if (iniscore == score) break;
	}
	for (int i = 0; i < K; i++) cout << vx[i] + 1 << ' ' << vy[i] + 1 << ' ' << vx[i] + 1 << ' ' << vy[i] + L[i] << endl;
	return 0;
}
0