結果

問題 No.5002 stick xor
ユーザー square1001square1001
提出日時 2018-05-26 11:41:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,544 bytes
コンパイル時間 35,022 ms
実行使用メモリ 1,628 KB
スコア 7,286
最終ジャッジ日時 2018-05-26 11:42:11
ジャッジサーバーID
(参考情報)
judge7 /
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <ctime>
#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;
	int u = clock();
	while (clock() - u < 0.99 * CLOCKS_PER_SEC) {
		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 cur = -1;
			vector<pair<int, int> > candy;
			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;
						candy.clear();
					}
					if (sum == cur) {
						candy.push_back(make_pair(j, k));
					}
				}
			}
			pair<int, int> pp = candy[rand() % candy.size()];
			int px = pp.first, py = pp.second;
			vx[i] = px;
			vy[i] = py;
			for (int j = py; j < py + L[i]; j++) x[px][j] ^= 1;
			score += cur * 2 - L[i];
		}
		//cout << score << endl;
	}
	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