結果

問題 No.223 1マス指定の魔方陣
コンテスト
ユーザー 184
提出日時 2015-06-05 23:19:29
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 783 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 695 ms
コンパイル使用メモリ 89,300 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-28 03:52:47
合計ジャッジ時間 6,950 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 1
other RE * 46
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:16:26: warning: 'z' is used uninitialized [-Wuninitialized]
   16 |         int n,x,y,z;scanf("%d%d%d%d",&n,&x,&y,z);
      |                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
main.cpp:16:19: note: 'z' was declared here
   16 |         int n,x,y,z;scanf("%d%d%d%d",&n,&x,&y,z);
      |                   ^

ソースコード

diff #
raw source code

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <set>

using namespace std;

//namaega184

int main(){
	int n,x,y,z;scanf("%d%d%d%d",&n,&x,&y,z);
	int a[21][21]={};
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			int b=n*i+j+1;
			if(b%4==1||b%4==0)a[i][j]=b; 
			else a[n-1-i][n-1-j]=b;
		}
	}
	int px=0,py=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(a[i][j]==z){px=j,py=i;break;}
		}
	}
	int b[21][21]={}; 
	px-=x,py-=y;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			b[i][j]=a[(j-py+n)%n][(i-px+n)%n];
		}
	} 
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(j==0)printf("%d",b[i][j]);
			else printf(" %d",b[i][j]);
		}
		puts("");
	}
	
	return 0; 
}
0