結果

問題 No.359 門松行列
ユーザー pekempeypekempey
提出日時 2016-04-18 00:11:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,899 bytes
コンパイル時間 1,529 ms
コンパイル使用メモリ 165,944 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 02:37:20
合計ジャッジ時間 3,183 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 8 ms
6,944 KB
testcase_04 AC 4 ms
6,944 KB
testcase_05 AC 7 ms
6,944 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 8 ms
6,940 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 72 ms
6,940 KB
testcase_14 AC 76 ms
6,944 KB
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

bool isKadomatsu(long long x, long long y, long long z) {
	if (x == y || y == z || x == z) return false;
	if (x > y && y < z) return true;
	if (x < y && y > z) return true;
	return false;
}

int a[3][3];

bool check() {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (a[i][j] == 0) return false;
		}
	}
	for (int i = 0; i < 3; i++) {
		if (!isKadomatsu(a[i][0], a[i][1], a[i][2])) return false;
		if (!isKadomatsu(a[0][i], a[1][i], a[2][i])) return false;
	}
	if (!isKadomatsu(a[0][0], a[1][1], a[2][2])) return false;
	if (!isKadomatsu(a[2][0], a[1][1], a[0][2])) return false;
	return true;
}

void solve() {
	int L;
	cin >> L;

	int y1 = -1, x1 = -1;
	int y2 = -1, x2 = -1;

	vector<int> b;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a[i][j];
			if (a[i][j] == 0) {
				if (y1 == -1) {
					y1 = i;
					x1 = j;
				} else {
					y2 = i;
					x2 = j;
				}
			} else {
				b.push_back(a[i][j]);
			}
		}
	}
	sort(b.begin(), b.end());

	vector<int> events;
	events.push_back(L);

	const int D = 1000;

	for (int j = L / 2 - D; j <= L / 2 + D; j++) { 
		if (0 < j && j < L) {
			events.push_back(j);
		}
	}

	for (int i = 0; i < b.size(); i++) {
		for (int j = b[i] - D; j <= b[i] + D; j++) {
			if (0 < j && j < L) {
				events.push_back(j);
			}
		}
	}
	for (int i = 0; i < b.size(); i++) {
		for (int j = L - b[i] - D; j <= L - b[i] + D; j++) {
			if (0 < j && j < L) {
				events.push_back(j);
			}
		}
	}
	sort(events.begin(), events.end());
	events.erase(unique(events.begin(), events.end()), events.end());

	int ans = 0;

	for (int i = 0; i < events.size() - 1; i++) {
		int x = events[i];
		int y = L - x;
		a[y1][x1] = x;
		a[y2][x2] = y;
		int len = events[i + 1] - events[i];
		if (check()) ans += len;
	}

	cout << ans << endl;
}

int main() {
	int T;
	cin >> T;
	while (T--) solve();
}
0