結果

問題 No.359 門松行列
ユーザー fumofumofunifumofumofuni
提出日時 2021-09-16 21:07:15
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,404 bytes
コンパイル時間 2,288 ms
コンパイル使用メモリ 212,364 KB
実行使用メモリ 8,768 KB
最終ジャッジ日時 2023-09-12 04:13:51
合計ジャッジ時間 7,015 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=2e9+1;
const ll INF=4e18;
const ll dy[8]={-1,0,1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}
bool iskd(ll a,ll b,ll c){
  if(a==b||b==c||c==a)return false;
  if(a<b&&b>c)return true;
  if(a>b&&b<c)return true;
  return false;
}
bool isok(vvl mat){
  rep(i,3)rep(j,3)if(mat[i][j]<=0)return false;
  bool ok=true;
  rep(i,3){
    ok&=iskd(mat[i][0],mat[i][1],mat[i][2]);
  }
  rep(i,3){
    ok&=iskd(mat[0][i],mat[1][i],mat[2][i]);
  }
  ok&=iskd(mat[0][0],mat[1][1],mat[2][2]);
  ok&=iskd(mat[0][2],mat[1][1],mat[2][0]);
  return ok;
}
void solve(){
  ll n;cin >> n;
  vvl mat(3,vl(3));
  vl x,y;
  rep(i,3){
    rep(j,3){
      cin >> mat[i][j];
      if(mat[i][j]==0){
        x.push_back(i);y.push_back(j);
      }
    }
  }
  vl st={1,n-1,n};
  rep(i,3)rep(j,3){
    st.push_back(mat[i][j]-1);
    st.push_back(mat[i][j]);
    st.push_back(mat[i][j]+1);
    st.push_back(n-mat[i][j]-1);
    st.push_back(n-mat[i][j]);
    st.push_back(n-mat[i][j]+1);
  }
  rep(i,10){
    st.push_back(n/2-5+i);
  }
  sort(all(st));st.erase(unique(all(st)),st.end());
  //for(auto p:st)cout << p <<" ";cout << endl;
  ll ans=0;
  rep(i,st.size()-1){
    mat[x[0]][y[0]]=st[i];
    mat[x[1]][y[1]]=n-st[i];
    if(isok(mat)){
      ans+=st[i+1]-st[i];
      //cout << st[i] << " ";
    }
  }
  cout << ans << endl;
  ll ret=0;
  for(int i=1;i<n-1;i++){
    mat[x[0]][y[0]]=i;
    mat[x[1]][y[1]]=n-i;
    if(isok(mat)){
      //cout << i <<" ";
      ret++;
    }
  }
  //cout << ret << endl;
}
int main(){
  ll t;cin >> t;
  while(t--){
    solve();
  }
}
0