結果

問題 No.359 門松行列
ユーザー rickythetarickytheta
提出日時 2016-04-18 15:19:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,696 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 69,612 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 03:29:48
合計ジャッジ時間 1,291 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 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 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:61:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   61 |   scanf("%d",&l);
      |   ~~~~~^~~~~~~~~
main.cpp:62:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   62 |   REP(i,3)REP(j,3)scanf("%d",&b[i][j]);
      |                   ~~~~~^~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:90:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   90 |   scanf("%d",&t);
      |   ~~~~~^~~~~~~~~

ソースコード

diff #

// #include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define REP(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=1;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)

#define DEBUG(x) cout<<(#x)<<": "<<(x)<<endl;

int l;
int a[3][3];
int b[3][3];

int c[3];

bool kado(){
  int x=c[0], y=c[1], z=c[2];
  return (x>y&&y<z&&x!=z)||(x<y&&y>z&&x!=z);
}

bool check(int val){
  if(val<=0 || val>=l)return false;
  int x = val;
  int y = l-x;
  int id = 0;
  REP(i,3)REP(j,3){
    if(a[i][j]==0){
      if(id==0)a[i][j] = x;
      else a[i][j] = y;
      id++;
    }
  }
  REP(i,3){
    REP(j,3)c[j]=a[i][j];
    if(!kado())return false;
  }
  REP(i,3){
    REP(j,3)c[j]=a[j][i];
    if(!kado())return false;
  }
  REP(i,3)c[i]=a[i][i];
  if(!kado())return false;
  REP(i,3)c[i]=a[2-i][i];
  if(!kado())return false;
  return true;
}

void solve(){
  scanf("%d",&l);
  REP(i,3)REP(j,3)scanf("%d",&b[i][j]);
  set<int> S;
  REP(i,3)REP(j,3)S.insert(b[i][j]);
  REP(i,3)REP(j,3)S.insert(l-b[i][j]);
  S.insert(l/2-1);
  S.insert(l/2);
  S.insert(l/2+1);
  set<int>::iterator iter = S.begin();
  int ans = 0;
  while(iter != S.end()){
    int x = *iter;
    iter++;
    if(iter==S.end())break;
    int y = *iter;
    REP(i,3)REP(j,3)a[i][j]=b[i][j];
    if(check(x)){
      ans += 1;
    }
    REP(i,3)REP(j,3)a[i][j]=b[i][j];
    if(x+1<y && check(x+1)){
      ans += y-x-1;
    }
  }
  printf("%d\n",ans);
}

int main(){
  int t;
  scanf("%d",&t);
  while(t--)solve();
  return 0;
}
0