結果

問題 No.223 1マス指定の魔方陣
ユーザー tubo28tubo28
提出日時 2015-06-05 23:14:24
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,871 bytes
コンパイル時間 1,363 ms
コンパイル使用メモリ 166,172 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-06 14:22:21
合計ジャッジ時間 4,623 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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
};

bool check(vvi g){
    int x = 0;
    int N = g.size();
    rep(i,N) x += g[0][i];
    bool exi[100] = {};
    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;
    vi arr;
    if(N==4) arr = vi(four,four+N*N);
    if(N==8) arr = vi(eight,eight+N*N);
    if(N==16) arr = vi(st,st+N*N);
    vvi g(N,vi(N));
    rep(i,N)rep(j,N) g[i][j] = arr[i*N+j];
    int ty = -1, tx = -1;
    rep(i,N)rep(j,N){
        if(g[i][j]==Z){
            ty = i, tx = j;
            break;
        }
    }
    X--, Y--;
    swap(g[Y],g[ty]);
    rep(i,N)rep(j,i) swap(g[i][j], g[j][i]);
    swap(g[X],g[tx]);
    rep(i,N)rep(j,i) swap(g[i][j], g[j][i]);

    rep(i,N)rep(j,N) cout << g[i][j] << (j==N-1 ? "\n" : " ");
    assert(check(g));
}
0