結果
| 問題 |
No.359 門松行列
|
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2016-03-23 22:07:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,925 bytes |
| コンパイル時間 | 937 ms |
| コンパイル使用メモリ | 100,828 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-10-01 21:38:58 |
| 合計ジャッジ時間 | 1,881 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 14 |
ソースコード
#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);
}
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;
}
koyumeishi