結果

問題 No.839 Keep Distance and Nobody Explodes
ユーザー knshnbknshnb
提出日時 2019-06-14 23:14:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 3,507 bytes
コンパイル時間 1,707 ms
コンパイル使用メモリ 172,088 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-09 07:12:12
合計ジャッジ時間 4,271 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 8 ms
4,376 KB
testcase_06 AC 8 ms
4,380 KB
testcase_07 AC 8 ms
4,380 KB
testcase_08 AC 9 ms
4,380 KB
testcase_09 AC 9 ms
4,376 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 7 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 6 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 6 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 5 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, unordered_map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int n; cin >> n;
  vector<vector<int>> t(n, vector<int>(n));
  if (n % 2 == 0) {
    int pt = 0;
    REP (k, n) {
      REP (i, n / 2) {
        int j = k - i;
        if (j < 0 || j >= n / 2) continue;
        t[i][j] = ++pt;
        t[n / 2 + i][n / 2 + j] = ++pt;
      }
    }

    REPI (k, -n, 0) {
      REP (i, n / 2) {
        int j = i - k;
        if (j < n / 2 || j >= n) continue;
        t[i][j] = ++pt;
        t[n / 2 + i][j - n / 2] = ++pt;
      }
    }
    assert(pt == n * n);
  } else {
    // t[n / 2][n / 2] = 1;
    int pt = 0;
    REP (k, n) {
      REP (i, n / 2 + 1) {
        int j = k - i;
        if (j < 0 || j >= n / 2 + 1) continue;
        t[n / 2 + i][n / 2 + j] = ++pt;
        if (i == n / 2 && j == n / 2) continue;
        t[i][j] = ++pt;
      }
    }

    REPI (k, -n, 0) {
      REP (i, n / 2) {
        int j = i - k;
        if (j <= n / 2 || j >= n) continue;
        t[i][j] = ++pt;
        t[n / 2 + 1 + i][j - (n / 2 + 1)] = ++pt;
      }
    }
  }
  REP (i, n) {
    REP (j, n) {
      cout << t[i][j] << " ";
    }
    cout << endl;
  }
}
0