結果

問題 No.217 魔方陣を作ろう
ユーザー kosakkunkosakkun
提出日時 2016-12-06 18:44:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 3,633 bytes
コンパイル時間 950 ms
コンパイル使用メモリ 100,192 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-28 03:11:32
合計ジャッジ時間 1,905 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 14 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
int main(){
int N; cin>>N;
int ans[100][100];
if(N%2==1){
int cnt=1;
int sy=0,sx=N/2;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
ans[sy][sx]=cnt;
cnt++;
sy=(sy-1+N)%N;
sx=(sx+1)%N;
}
sy=(sy+2)%N;
sx=(sx-1+N)%N;
}
}
if((N-2)%4==0){
int Nt=N/2;
int add[100][100];
int cnt=1;
int sy=0,sx=Nt/2;
for(int i=0;i<Nt;i++){
for(int j=0;j<Nt;j++){
add[sy][sx]=cnt;
cnt++;
sy=(sy-1+Nt)%Nt;
sx=(sx+1)%Nt;
}
sy=(sy+2)%Nt;
sx=(sx-1+Nt)%Nt;
}
REP(i,N)REP(j,N){
ans[i][j]=add[i/2][j/2];
}
int add2[100][100];
REP(i,N/2)REP(j,N/2){
if(i==N/4&&j==N/4){
add2[i*2 ][j*2 ]=1;
add2[i*2 ][j*2+1]=4;
add2[i*2+1][j*2 ]=2;
add2[i*2+1][j*2+1]=3;
}else if(i==N/4+1){
if(j!=N/4){
add2[i*2 ][j*2 ]=1;
add2[i*2 ][j*2+1]=4;
add2[i*2+1][j*2 ]=2;
add2[i*2+1][j*2+1]=3;
}else{
add2[i*2 ][j*2 ]=4;
add2[i*2 ][j*2+1]=1;
add2[i*2+1][j*2 ]=2;
add2[i*2+1][j*2+1]=3;
}
}else if(i<N/4){
add2[i*2 ][j*2 ]=4;
add2[i*2 ][j*2+1]=1;
add2[i*2+1][j*2 ]=2;
add2[i*2+1][j*2+1]=3;
}else{
add2[i*2 ][j*2 ]=1;
add2[i*2 ][j*2+1]=4;
add2[i*2+1][j*2 ]=3;
add2[i*2+1][j*2+1]=2;
}
}
REP(i,100)REP(j,100)ans[i][j]+=add2[i][j];
}
if(N%4==0){
REP(i,N/4)REP(j,N/4){
ans[i*4 ][j*4 ]=1;
ans[i*4 ][j*4+3]=1;
ans[i*4+1][j*4+1]=1;
ans[i*4+1][j*4+2]=1;
ans[i*4+2][j*4+1]=1;
ans[i*4+2][j*4+2]=1;
ans[i*4+3][j*4 ]=1;
ans[i*4+3][j*4+3]=1;
}
int cnt=1;
set<int> used;
REP(i,N)REP(j,N){
if(ans[i][j]==1){
ans[i][j]=cnt;
used.insert(cnt);
}
cnt++;
}
cnt=1;
RREP(i,N)RREP(j,N){
if(ans[i][j]==0){
while(used.find(cnt)!=used.end())cnt++;
ans[i][j]=cnt;
used.insert(cnt);
}
}
}
REP(i,N){
REP(j,N-1)cout<<ans[i][j]<<" ";
cout<<ans[i][N-1]<<endl;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0