結果

問題 No.1831 Parasol
コンテスト
ユーザー siman
提出日時 2022-02-06 11:50:49
言語 C++17(clang)
(clang++ 21.1.8 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,090 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,443 ms
コンパイル使用メモリ 147,200 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2026-03-04 14:58:23
合計ジャッジ時間 2,658 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:19:22: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   19 |   int mapping[2 * N][2 * N];
      |                      ^~~~~
main.cpp:19:26: note: read of non-const variable 'N' is not allowed in a constant expression
   19 |   int mapping[2 * N][2 * N];
      |                          ^
main.cpp:17:7: note: declared here
   17 |   int N;
      |       ^
main.cpp:19:15: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   19 |   int mapping[2 * N][2 * N];
      |               ^~~~~
main.cpp:19:19: note: read of non-const variable 'N' is not allowed in a constant expression
   19 |   int mapping[2 * N][2 * N];
      |                   ^
main.cpp:17:7: note: declared here
   17 |   int N;
      |       ^
main.cpp:35:18: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   35 |   int ans[2 * N][N];
      |                  ^
main.cpp:35:18: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
   17 |   int N;
      |       ^
main.cpp:35:11: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   35 |   int ans[2 * N][N];
      |           ^~~~~
main.cpp:35:15: note: read of non-const variable 'N' is not allowed in a constant expression
   35 |   int ans[2 * N][N];
      |               ^
main.cpp:17:7: note: declared here
   17 |   int N;
      |       ^
4 warnings generated.

ソースコード

diff #
raw source code

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  int mapping[2 * N][2 * N];
  memset(mapping, -1, sizeof(mapping));

  for (int x = 2 * N - 1; x >= 1; --x) {
    if (x % 2 == 0) {
      for (int y = 1; y <= x; ++y) {
        mapping[y][x] = 2 * N - y;
      }
    } else {
      for (int y = x; y >= 1; --y) {
        mapping[y][x] = x - y + 1;
      }
    }
  }

  vector<int> counter(2 * N, 0);
  int ans[2 * N][N];
  for (int y = 1; y <= 2 * N - 1; ++y) {
    for (int x = 1; x <= 2 * N - 1; ++x) {
      int id = mapping[y][x];
      if (id == -1) continue;

      int idx = counter[id];
      ans[id][idx] = x;
      counter[id]++;
    }
  }

  cout << 2 * N - 1 << endl;
  for (int id = 1; id <= 2 * N - 1; ++id) {
    for (int i = 0; i < N; ++i) {
      cout << ans[id][i];
      if (i != N - 1) cout << " ";
    }
    cout << endl;
  }

  return 0;
}
0