結果

問題 No.1169 Row and Column and Diagonal
ユーザー tko919tko919
提出日時 2020-08-14 21:41:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 945 bytes
コンパイル時間 1,674 ms
コンパイル使用メモリ 166,044 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 21:17:37
合計ジャッジ時間 2,734 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

int a[510][510];

int main(){
   int n; cin>>n;
   rep(i,0,n)a[i][i]=i+1;
   int v=2;
   for(int i=2;i<n;i+=2,v++)a[0][i]=v;
   for(int i=1;i<n;i+=2,v++)a[0][i]=v;
   vector<int> b;
   rep(i,0,n)b.push_back(a[0][i]);
   rep(i,1,n){
      int s=-1;
      rep(j,0,n)if(b[j]==i+1){
         s=j; break;
      }
      for(int j=i,k=s,c=0;c<n;j=(j+1)%n,k=(k+1)%n,c++){
         a[i][j]=b[k];
      }
   }
   rep(i,0,n){
      rep(j,0,n)cout<<a[i][j]<<' ';
      cout<<'\n';
   }
   return 0;
}
0