結果

問題 No.359 門松行列
ユーザー koyumeishikoyumeishi
提出日時 2016-03-23 22:10:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,964 bytes
コンパイル時間 915 ms
コンパイル使用メモリ 100,636 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-09 21:12:07
合計ジャッジ時間 1,715 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <set>
#include <ctime>
#include <random>
#include <chrono>
using namespace std;

template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;}
template<class T> istream& operator ,  (istream& is, T& val){ return is >> val;}
template<class T> ostream& operator << (ostream& os, const vector<T>& vec){for(int i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"":" "); return os;}
template<class T> ostream& operator ,  (ostream& os, const T& val){ return os << " " << val;}
template<class T> ostream& operator >> (ostream& os, const T& val){ return os << " " << val;}

bool is_kadomatsu(int a, int b, int c){
	return a!=c && ((a<b&&b>c) || (a>b&&b<c));
}
bool is_kadomatsu_mat(vector<int> v){
	for(int r=0; r<3; r++) if(is_kadomatsu(v[3*r+0],v[3*r+1],v[3*r+2]) == false) return false;
	for(int c=0; c<3; c++) if(is_kadomatsu(v[3*0+c],v[3*1+c],v[3*2+c]) == false) return false;
	if(is_kadomatsu(v[3*0+0],v[3*1+1],v[3*2+2]) == false) return false;
	if(is_kadomatsu(v[3*0+2],v[3*1+1],v[3*2+0]) == false) return false;
	return true;
}

int main(){
	int t;
	cin >> t;
	while(t--){
		int L;
		cin >> L;
		vector<int> v(9);
		cin >> v;
		set<int> s;
		vector<int> p;
		for(int i=0; i<v.size(); i++){
			int x = v[i];
			for(int d:{-1,0,1}) s.insert(x+d), s.insert(L-(x+d));
			if(x==0) p.push_back(i);
		}
		for(int d:{-1,0,1}) s.insert(L/2+d);

		int ans  = 0;
		int last = 0;
		int cond = 0;
		for(int val : s){
			if(val<=0 || L<=val) continue;
			if(L-val<=0 || L<=L-val) continue;
			v[p[0]] = val;
			v[p[1]] = L-val;
			if(is_kadomatsu_mat(v)){
				if(cond){
					ans += val - last;
				}else{
					ans += 1;
				}
				cond = 1;
			}else{
				cond = 0;
			}
			last = val;
		}

		cout << ans << endl;

	}
	return 0;
}
0