結果

問題 No.217 魔方陣を作ろう
ユーザー kosakkunkosakkun
提出日時 2016-12-06 18:14:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,276 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 91,032 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 19:34:52
合計ジャッジ時間 2,098 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 WA -
testcase_14 AC 2 ms
4,376 KB
testcase_15 WA -
testcase_16 AC 2 ms
4,380 KB
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
        }
    }
    
    REP(i,N){
        REP(j,N-1)cout<<ans[i][j]<<" ";
        cout<<ans[i][N-1]<<endl;
    }
    
    return 0;
}



0