結果

問題 No.5002 stick xor
ユーザー square1001square1001
提出日時 2018-05-26 11:46:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 996 ms / 1,000 ms
コード長 1,545 bytes
コンパイル時間 34,721 ms
実行使用メモリ 1,628 KB
スコア 38,369
最終ジャッジ日時 2018-05-26 11:47:13
ジャッジサーバーID
(参考情報)
judge9 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 976 ms
1,628 KB
testcase_01 AC 987 ms
1,624 KB
testcase_02 AC 983 ms
1,628 KB
testcase_03 AC 990 ms
1,624 KB
testcase_04 AC 976 ms
1,624 KB
testcase_05 AC 981 ms
1,628 KB
testcase_06 AC 981 ms
1,628 KB
testcase_07 AC 987 ms
1,620 KB
testcase_08 AC 979 ms
1,624 KB
testcase_09 AC 981 ms
1,624 KB
testcase_10 AC 984 ms
1,624 KB
testcase_11 AC 980 ms
1,628 KB
testcase_12 AC 981 ms
1,624 KB
testcase_13 AC 991 ms
1,620 KB
testcase_14 AC 987 ms
1,624 KB
testcase_15 AC 987 ms
1,628 KB
testcase_16 AC 979 ms
1,624 KB
testcase_17 AC 979 ms
1,628 KB
testcase_18 AC 989 ms
1,624 KB
testcase_19 AC 980 ms
1,628 KB
testcase_20 AC 994 ms
1,628 KB
testcase_21 AC 981 ms
1,628 KB
testcase_22 AC 980 ms
1,624 KB
testcase_23 AC 978 ms
1,620 KB
testcase_24 AC 988 ms
1,628 KB
testcase_25 AC 979 ms
1,624 KB
testcase_26 AC 996 ms
1,628 KB
testcase_27 AC 979 ms
1,624 KB
testcase_28 AC 982 ms
1,624 KB
testcase_29 AC 988 ms
1,628 KB
testcase_30 AC 986 ms
1,624 KB
testcase_31 AC 987 ms
1,624 KB
権限があれば一括ダウンロードができます

ソースコード

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.970 * 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