結果

問題 No.3722 Blended Taste
コンテスト
ユーザー テナガザル
提出日時 2026-09-19 13:17:15
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 962 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 996 ms
コンパイル使用メモリ 173,648 KB
実行使用メモリ 12,760 KB
最終ジャッジ日時 2026-09-19 13:27:25
合計ジャッジ時間 4,814 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 37 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> a(n, vector<int> (n));
  vector<int> cnt(m + 1, n * n / m);
  cnt[0] = 0;
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
      int x = i % k, y = j % k;
      int tmp = x * k + y + 1;
      if (tmp <= m)
      {
        a[i][j] = tmp;
        --cnt[tmp];
      }
    }
  }
  vector<int> nok;
  for (int i = 1; i <= m; ++i)
  {
    if (cnt[i] < 0)
    {
      cout << -1 << endl;
      return 0;
    }
    while (cnt[i] > 0)
    {
      --cnt[i];
      nok.push_back(i);
    }
  }
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
      if (a[i][j] == 0)
      {
        a[i][j] = nok.back();
        nok.pop_back();
      }
    }
  }
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
      cout << a[i][j] << " \n"[j == n - 1];
    }
  }
}
0