結果
| 問題 |
No.223 1マス指定の魔方陣
|
| コンテスト | |
| ユーザー |
kmjp
|
| 提出日時 | 2015-06-05 22:59:13 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,072 bytes |
| コンパイル時間 | 1,479 ms |
| コンパイル使用メモリ | 165,824 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-06 14:20:40 |
| 合計ジャッジ時間 | 4,078 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 12 WA * 27 RE * 7 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
int N,X,Y,Z;
int pat[16][16];
int patt[10][4][4]={
{{1,1,0,0},{0,0,1,1},{1,1,0,0},{0,0,1,1}},
{{1,0,1,0},{0,1,0,1},{0,1,0,1},{1,0,1,0}},
{{1,1,0,0},{0,0,1,1},{0,0,1,1},{1,1,0,0}},
{{1,1,0,0},{1,1,0,0},{1,0,1,0},{0,0,1,1}},
{{0,1,0,1},{1,1,0,0},{0,0,1,1},{1,0,1,0}},
{{1,0,1,0},{1,0,1,0},{0,1,0,1},{0,1,0,1}},
{{1,0,0,1},{0,1,1,0},{1,0,0,1},{0,1,1,0}},
{{1,0,0,1},{1,0,0,1},{0,1,1,0},{0,1,1,0}},
{{1,1,0,0},{1,0,1,0},{0,1,0,1},{0,0,1,1}},
{{0,1,0,1},{1,1,0,0},{0,0,1,1},{1,0,1,0}},
};
void dodo(int yy,int xx,int zz) {
int a,b,c,d;
int y,x;
FOR(a,10) FOR(b,10) FOR(c,10) FOR(d,10) {
if(zz!=patt[a][yy][xx]*8+patt[b][yy][xx]*4+patt[c][yy][xx]*2+patt[d][xx][yy]) continue;
set<int> S;
FOR(y,4) FOR(x,4) pat[y][x]=patt[a][y][x]*8+patt[b][y][x]*4+patt[c][y][x]*2+patt[d][x][y], S.insert(pat[y][x]);
if(S.size()!=16) continue;
int ng=0;
FOR(y,4) {
int t=0;
FOR(x,4) t+=pat[y][x];
if(t!=30) ng++;
}
FOR(x,4) {
int t=0;
FOR(y,4) t+=pat[y][x];
if(t!=30) ng++;
}
if(pat[0][0]+pat[1][1]+pat[2][2]+pat[3][3]!=30) ng++;
if(pat[0][3]+pat[1][2]+pat[2][1]+pat[3][0]!=30) ng++;
if(ng==0) return;
}
assert(0);
}
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N>>X>>Y>>Z;
X--;
Y--;
Z--;
if(N==4) {
dodo(Y,X,Z);
}
else if(N==8) {
dodo(Y%4,X%4,Z%16);
}
else if(N==16) {
dodo(Y%4,X%4,Z%16);
}
FOR(y,N) {
FOR(x,N) _P("%d%c",pat[y][x]+1,(x==N-1)?'\n':' ');
}
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false);
FOR(i,argc-1) s+=argv[i+1],s+='\n';
FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
solve(); return 0;
}
kmjp