結果

問題 No.359 門松行列
ユーザー mamekin
提出日時 2016-04-17 23:10:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,251 bytes
コンパイル時間 1,218 ms
コンパイル使用メモリ 115,164 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-10 23:58:08
合計ジャッジ時間 2,080 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;
bool checkKadomatsu(const vector<int>& a)
{
if(a[0] == a[2])
return false;
return (a[0] < a[1] && a[2] < a[1]) || (a[0] > a[1] && a[2] > a[1]);
}
bool checkKadomatsu(const vector<vector<int> >& a)
{
for(int i=0; i<3; ++i){
vector<int> b(3), c(3);
for(int j=0; j<3; ++j){
b[j] = a[i][j];
c[j] = a[j][i];
}
if(!checkKadomatsu(b) || !checkKadomatsu(c))
return false;
}
vector<int> b(3), c(3);
for(int i=0; i<3; ++i){
b[i] = a[i][i];
c[i] = a[i][2-i];
}
return checkKadomatsu(b) && checkKadomatsu(c);
}
int main()
{
int t;
cin >> t;
while(--t >= 0){
int len;
cin >> len;
vector<vector<int> > a(3, vector<int>(3));
vector<int> y, x;
set<int> s;
s.insert(1);
s.insert(len);
s.insert(len/2-1);
s.insert(len/2);
s.insert(len/2+1);
for(int i=0; i<3; ++i){
for(int j=0; j<3; ++j){
cin >> a[i][j];
if(a[i][j] == 0){
y.push_back(i);
x.push_back(j);
}
else{
for(int k=-1; k<=1; ++k){
s.insert(a[i][j] + k);
s.insert(len - a[i][j] + k);
}
}
}
}
vector<int> v(s.begin(), s.end());
int ans = 0;
for(unsigned i=0; i<v.size()-1; ++i){
int p = v[i];
int q = v[i+1];
if(!(0 < p && p < len))
continue;
a[y[0]][x[0]] = p;
a[y[1]][x[1]] = len - p;
if(checkKadomatsu(a))
ans += q - p;
}
cout << ans << endl;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0