結果

問題 No.359 門松行列
ユーザー 🐬hec🐬hec
提出日時 2016-04-18 03:19:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,807 bytes
コンパイル時間 2,287 ms
コンパイル使用メモリ 173,328 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 03:20:48
合計ジャッジ時間 2,545 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) (sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg)))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

bool check(int a,int b,int c){
	if(a==b) return false;
	if(b==c) return false;
	if(c==a) return false;

	if(min({a,b,c})==b) return true;
	if(max({a,b,c})==b) return true;

	return false;
}

bool check(int a[3][3]){
	rep(i,3) if(check(a[i][0],a[i][1],a[i][2])==false) return false;
	rep(i,3) if(check(a[0][i],a[1][i],a[2][i])==false) return false;
	if(check(a[0][0],a[1][1],a[2][2])==false) return false;
	if(check(a[0][2],a[1][1],a[2][0])==false) return false;
	return true;
}

int main(void){
	int t;
	cin >> t;
	rep(loop,t){
		int L,a[3][3];
		cin >> L;
		rep(i,3)rep(j,3) cin >> a[i][j];

		int ans=0;
		int r[2]={-1,-1},c[2];
		rep(i,3)rep(j,3){
			if(a[i][j]==0){
				if(r[0]==-1)
					r[0]=i,c[0]=j;
				else
					r[1]=i,c[1]=j;
			}
		} 

		vector<int> boader;
		boader.push_back(0);
		boader.push_back(L);
		if(L/2*2==L) boader.push_back(L/2);

		rep(i,2){
			rep(j,3){
				if(i==1) 
					boader.push_back(L-a[j][c[i]]);
				else
					boader.push_back(a[j][c[i]]);
			}
			rep(j,3){
				if(i==1) 
					boader.push_back(L-a[r[i]][j]);
				else
					boader.push_back(a[r[i]][j]);
			}

			if(r[i]==c[i]){
				rep(j,3){
					if(i==1) 
						boader.push_back(L-a[j][j]);
					else
						boader.push_back(a[j][j]);
				}
			}
			if(r[i]+c[i]==2){
				rep(j,3){
					if(i==1) 
						boader.push_back(L-a[2-j][j]);
					else
						boader.push_back(a[2-j][j]);
				}
			}
		}

		uniq(boader);
		int n=boader.size();
		
		rep(i,n-1){
			const int zero=(boader[i]+boader[i+1])/2;
			const int one=L-zero;
			if(zero < 0 || one < 0) continue;
			int tmp[3][3];
			rep(j,3)rep(k,3) tmp[j][k]=a[j][k];
			tmp[r[0]][c[0]]=zero,tmp[r[1]][c[1]]=one;
			
			if(check(tmp)) ans+=boader[i+1]-boader[i]-1;
		}

		if(L/2*2==L){
			int tmp[3][3];
			rep(j,3)rep(k,3) tmp[j][k]=a[j][k];
			tmp[r[0]][c[0]]=L/2,tmp[r[1]][c[1]]=L/2;
			if(check(tmp)) ans++;
		}

		cout << ans << endl;		
	}	
	return 0;
}
0