結果

問題 No.1169 Row and Column and Diagonal
ユーザー keijakkeijak
提出日時 2020-08-15 06:41:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 1,460 bytes
コンパイル時間 2,367 ms
コンパイル使用メモリ 204,308 KB
実行使用メモリ 27,904 KB
最終ジャッジ日時 2024-04-18 23:40:09
合計ジャッジ時間 4,102 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 8 ms
5,376 KB
testcase_07 AC 20 ms
7,936 KB
testcase_08 AC 34 ms
11,136 KB
testcase_09 AC 55 ms
14,848 KB
testcase_10 AC 120 ms
24,448 KB
testcase_11 AC 128 ms
26,624 KB
testcase_12 AC 135 ms
27,520 KB
testcase_13 AC 144 ms
27,648 KB
testcase_14 AC 139 ms
27,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
template <typename T>
using V = std::vector<T>;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T>
void debug(const vector<T>& v) {
  cerr << '[';
  for (int i = 0; i < (int)v.size(); ++i) {
    debug(v[i]);
    if (i < (int)v.size() - 1) cerr << ", ";
  }
  cerr << ']';
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  V<set<int>> rows(n), cols(n);
  V<V<int>> a(n, V<int>(n));
  for (int k = 1; k <= n; ++k) {
    int r = k - 1, c = k - 1;
    while (a[r][c] == 0 && !rows[r].count(k) && !cols[c].count(k)) {
      a[r][c] = k;
      rows[r].insert(k);
      cols[c].insert(k);
      c = (c + 1) % n;
      r = (r + 2) % n;
    }
  }
  REP(i, n) {
    REP(j, n) { cout << a[i][j] << (j == n - 1 ? '\n' : ' '); }
  }
}
0