結果

問題 No.223 1マス指定の魔方陣
ユーザー tubo28tubo28
提出日時 2015-06-05 23:51:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 3,836 bytes
コンパイル時間 1,056 ms
コンパイル使用メモリ 144,164 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 19:28:54
合計ジャッジ時間 3,272 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define int ll
//#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
template<class T> inline bool chmax(T & x, T const & y){ return x<y ? x=y,true : false; }
template<class T> inline bool chmin(T & x, T const & y){ return x>y ? x=y,true : false; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif
// ll const mod = 1000000007;
// ll const inf = 1LL<<60;

int four[] = {
1,15,14,4,
12,6,7,9,
8,10,11,5,
13,3,2,16
};

int eight[] = {
1,63,62,4,5,59,58,8,
56,10,11,53,52,14,15,49,
48,18,19,45,44,22,23,41,
25,39,38,28,29,35,34,32,
33,31,30,36,37,27,26,40,
24,42,43,21,20,46,47,17,
16,50,51,13,12,54,55,9,
57,7,6,60,61,3,2,64
};

int st[] = {
1,255,254,4,5,251,250,8,9,247,246,12,13,243,242,16,
240,18,19,237,236,22,23,233,232,26,27,229,228,30,31,225,
224,34,35,221,220,38,39,217,216,42,43,213,212,46,47,209,
49,207,206,52,53,203,202,56,57,199,198,60,61,195,194,64,
65,191,190,68,69,187,186,72,73,183,182,76,77,179,178,80,
176,82,83,173,172,86,87,169,168,90,91,165,164,94,95,161,
160,98,99,157,156,102,103,153,152,106,107,149,148,110,111,145,
113,143,142,116,117,139,138,120,121,135,134,124,125,131,130,128,
129,127,126,132,133,123,122,136,137,119,118,140,141,115,114,144,
112,146,147,109,108,150,151,105,104,154,155,101,100,158,159,97,
96,162,163,93,92,166,167,89,88,170,171,85,84,174,175,81,
177,79,78,180,181,75,74,184,185,71,70,188,189,67,66,192,
193,63,62,196,197,59,58,200,201,55,54,204,205,51,50,208,
48,210,211,45,44,214,215,41,40,218,219,37,36,222,223,33,
32,226,227,29,28,230,231,25,24,234,235,21,20,238,239,17,
241,15,14,244,245,11,10,248,249,7,6,252,253,3,2,256
};

template<class T>
bool check(T g){
    int x = 0;
    int N = g.size();
    rep(i,N) x += g[0][i];
    bool exi[500] = {};
    rep(i,N){
        int s = 0;
        rep(j,N){
            if(exi[g[i][j]]) return false;
            exi[g[i][j]] = true;
        }
        rep(j,N) s += g[i][j];
        int t = 0;
        rep(j,N) t += g[j][i];
        dump(s,t);
        if(s!=x) return false;
        if(t!=x) return false;
    }
    return true;
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int N,X,Y,Z;
    cin >> N >> X >> Y >> Z;
    Z--;
    int * arr;
    if(N==4) arr = four;
    if(N==8) arr = eight;
    if(N==16) arr = st;
    static int g[1000][1000];
    rep(i,N)rep(j,N) g[i][j] = arr[i*N+j]-1;
    int ty = -1, tx = -1;
    rep(i,N)rep(j,N){
        if(g[i][j]==Z){
            ty = i, tx = j;
            break;
        }
    }
    X--, Y--;
    int t = g[Y][X];
    rep(i,N)rep(j,N){
        g[i][j] ^= t;
        g[i][j] ^= Z;
    }
    rep(i,N)rep(j,N) cout << g[i][j]+1 << (j==N-1 ? "\n" : " ");
    //assert(check(g));
}
0