結果

問題 No.359 門松行列
ユーザー chocoruskchocorusk
提出日時 2020-01-01 15:33:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 2,003 bytes
コンパイル時間 1,436 ms
コンパイル使用メモリ 121,024 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 10:20:31
合計ジャッジ時間 2,419 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:80:55: 警告: ‘y2’ may be used uninitialized [-Wmaybe-uninitialized]
   80 |                                 a[x1][y1]=x, a[x2][y2]=l-x;
      |                                              ~~~~~~~~~^~~~
main.cpp:48:39: 備考: ‘y2’ はここで定義されています
   48 |                 int x1=-1, y1=-1, x2, y2;
      |                                       ^~
main.cpp:80:55: 警告: ‘x2’ may be used uninitialized [-Wmaybe-uninitialized]
   80 |                                 a[x1][y1]=x, a[x2][y2]=l-x;
      |                                              ~~~~~~~~~^~~~
main.cpp:48:35: 備考: ‘x2’ はここで定義されています
   48 |                 int x1=-1, y1=-1, x2, y2;
      |                                   ^~

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int l;
int a[3][3];
int main()
{
	int t;
	cin>>t;
	auto check1=[&](int x, int y, int z){
		if(x!=z && ((x<y && y>z) || (x>y && y<z))) return true;
		else return false;
	};
	auto check=[&](){
		for(int i=0; i<3; i++) if(!check1(a[i][0], a[i][1], a[i][2])) return false;
		for(int i=0; i<3; i++) if(!check1(a[0][i], a[1][i], a[2][i])) return false;
		if(!check1(a[0][0], a[1][1], a[2][2])) return false;
		if(!check1(a[0][2], a[1][1], a[2][0])) return false;
		return true;
	};
	for(int z=0; z<t; z++){
		cin>>l;
		vector<int> v;
		int x1=-1, y1=-1, x2, y2;
		for(int i=0; i<3; i++){
			for(int j=0; j<3; j++){
				cin>>a[i][j];
				if(a[i][j]>0) v.push_back(a[i][j]);
				else if(x1==-1) x1=i, y1=j;
				else x2=i, y2=j;
			}
		}
		if(l==1){
			cout<<0<<endl;
			continue;
		}
		v.push_back(l/2);
		v.push_back((l+1)/2);
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());
		int m=v.size();
		vector<P> w;
		for(int i=0; i<m; i++){
			if(i<m-1 && v[i]+1<=v[i+1]-1) w.push_back({v[i]+1, v[i+1]-1});
			w.push_back({v[i], v[i]});
		}
		if(1<=v[0]-1) w.push_back({1, v[0]-1});
		if(v[m-1]+1<=l-1) w.push_back({v[m-1]+1, l-1});
		int k=w.size();
		int ans=0;
		for(int i=0; i<k; i++){
			for(int j=0; j<k; j++){
				int x=l-w[j].second, y=l-w[j].first;
				x=max(x, w[i].first), y=min(y, w[i].second);
				if(x<=0 || y>=l || x>y) continue;
				a[x1][y1]=x, a[x2][y2]=l-x;
				if(check()) ans+=y-x+1;
			}
		}
		cout<<ans<<endl;
	}
 	return 0;
}
0