結果
| 問題 |
No.359 門松行列
|
| コンテスト | |
| ユーザー |
rickytheta
|
| 提出日時 | 2016-04-18 15:19:42 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,696 bytes |
| コンパイル時間 | 533 ms |
| コンパイル使用メモリ | 69,620 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-04 13:33:30 |
| 合計ジャッジ時間 | 1,155 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
コンパイルメッセージ
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);
| ~~~~~^~~~~~~~~
ソースコード
// #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;
}
rickytheta