結果

問題 No.217 魔方陣を作ろう
ユーザー tailstails
提出日時 2015-05-10 17:40:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 584 bytes
コンパイル時間 1,696 ms
コンパイル使用メモリ 144,408 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 02:07:44
合計ジャッジ時間 2,688 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int N;
int A[32][32];

int L[]={4,1,2,3};
int U[]={1,4,2,3};
int X[]={1,4,3,2};

int f(int n,int y,int x){
	if(n&1){
		int v=(x+y+n/2+1)%n;
		int u=(x+v+n/2+1)%n;
		return v*n+u+1;
	}
	if(n&2){
		// LUX method
		int* LUX = y>n/2+2 ? X : (x/2==n/4?x/2==y/2:y>n/2) ? U : L;
		return f(n/2,y/2,x/2)*4-4+LUX[x&1|(y&1)<<1];
	}
	{
		int i=y*n+x;
		return ((y+n/4)/(n/2)^(x+n/4)/(n/2))&1 ? n*n-i : i+1;
	}
}

int main() {
	cin>>N;

	for(int y=0;y<N;++y){
		for(int x=0;x<N;++x){
			cout << f(N,y,x) << " ";
		}
		cout << endl;
	}

	return 0;
}
0