結果

問題 No.3722 Blended Taste
コンテスト
ユーザー nyanpasu
提出日時 2026-09-19 13:30:50
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 15,677 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,008 ms
コンパイル使用メモリ 395,804 KB
実行使用メモリ 19,200 KB
最終ジャッジ日時 2026-09-19 13:32:32
合計ジャッジ時間 9,158 ms
ジャッジサーバーID
(参考情報)
judge5_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 29 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define sz(x) ((int64_t)x.size())
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define in_grid(h, w, H, W) if (!(0 <= h && 0 <= w && h < H && w < W)) continue;
template<typename T> using priority_queue_g = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using vec = vector<T>;

//プロトタイプ宣言
template <typename T> istream &operator>>(istream &is, vector<T> &v);
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v);
template <typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v);
template <typename T> ostream &operator<<(ostream &os, const vector<vector<vector<T>>> &v);
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p);
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> & p);
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &m);
template <typename T> ostream &operator<<(ostream &os, const set<T> &s);
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &s);
template <typename T> ostream &operator<<(ostream &os, queue<T> q);
template <class T, class Container, class Compare> ostream &operator<<(ostream &os, priority_queue<T, Container, Compare> q);
template <typename T> ostream &operator<<(ostream &os, stack<T> s);
istream &operator>>(istream &is, modint &i);
istream &operator>>(istream &is, modint998244353 &i);
istream &operator>>(istream &is, modint1000000007 &i);
ostream &operator<<(ostream &os, const modint &i);
ostream &operator<<(ostream &os, const modint998244353 &i);
ostream &operator<<(ostream &os, const modint1000000007 &i);

//vector
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T & in : v) is >> in;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    bool first = true;
    for (const auto &x : v) {
        if (!first) os << " ";
        os << x;
        first = false;
    }
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
    bool first = true;
    for (const auto &x : v) {
        if (!first) os << "\n";
        os << x;
        first = false;
    }
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<vector<vector<T>>> &v) {
    bool first = true;
    for (const auto &x : v) {
        if (!first) os << "\n\n";
        os << x;
        first = false;
    }
    return os;
}

//pair
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
    is >> p.first >> p.second;
    return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

//map
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &m) {
    bool first = true;
    for (const auto &[key, val] : m) {
        if (!first) os << " ";
        os << key << ":" << val;
        first = false;
    }
    return os;
}

//set
template <typename T>
ostream &operator<<(ostream &os, const set<T> &s) {
    bool first = true;
    for (const auto &x : s) {
        if (!first) os << " ";
        os << x;
        first = false;
    }
    return os;
}

//multiset
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &s) {
    bool first = true;
    for (const auto &x : s) {
        if (!first) os << " ";
        os << x;
        first = false;
    }
    return os;
}

//queue
template <typename T>
ostream &operator<<(ostream &os, queue<T> q) {
    bool first = true;
    while (!q.empty()) {
        if (!first) os << " ";
        os << q.front();
        q.pop();
        first = false;
    }
    return os;
}

//priority_queue
template <class T, class Container, class Compare>
ostream &operator<<(ostream &os, priority_queue<T, Container, Compare> q) {
    bool first = true;
    while (!q.empty()) {
        if (!first) os << " ";
        os << q.top();
        q.pop();
        first = false;
    }
    return os;
}

//stack
template <typename T>
ostream &operator<<(ostream &os, stack<T> s) {
    bool first = true;
    while (!s.empty()) {
        if (!first) os << " ";
        os << s.top();
        s.pop();
        first = false;
    }
    return os;
}

//modint
istream &operator>>(istream &is, modint &i) {
    int64_t x;
    is >> x;
    i = x;
    return is;
}
istream &operator>>(istream &is, modint998244353 &i) {
    int64_t x;
    is >> x;
    i = x;
    return is;
}
istream &operator>>(istream &is, modint1000000007 &i) {
    int64_t x;
    is >> x;
    i = x;
    return is;
}
ostream &operator<<(ostream &os, const modint &i) {
    os << i.val();
    return os;
}
ostream &operator<<(ostream &os, const modint998244353 &i) {
    os << i.val();
    return os;
}
ostream &operator<<(ostream &os, const modint1000000007 &i) {
    os << i.val();
    return os;
}

//複数ベクター同時受け取り
template <typename T, typename... Ts>
void vcin(vector<T> &first, vector<Ts> &... rest) {
    vector<size_t> sizes = {rest.size()...};
    for (auto sz : sizes) {
        if (sz != first.size()) {
            cerr << "vcinエラー サイズが異なります" << "\n";
            assert(false);
        }
    }
    for (int i = 0; i < (int)first.size(); i++) {
        cin >> first[i], (cin >> ... >> rest[i]);
    }
}

//ジャグ配列
template <typename T>
void jagcin(vector<vector<T>> &vv) {
    for (auto &v : vv) {
        int k;
        cin >> k;
        v.resize(k);
        for (int i = 0; i < k; i++) {
            cin >> v[i];
        }
    }
}

//map
template <typename T1, typename T2>
void mapcin(map<T1, T2> &m, int n) {
    for (int i = 0; i < n; i++) {
        T1 x; T2 y;
        cin >> x >> y;
        m[x] = y;
    }
}

//set
template <typename T>
void setcin(set<T> &s, int n) {
    for (int i = 0; i < n; i++) {
        T x;
        cin >> x;
        s.insert(x);
    }
}

//multiset
template <typename T>
void setcin(multiset<T> &s, int n) {
    for (int i = 0; i < n; i++) {
        T x;
        cin >> x;
        s.insert(x);
    }
}

//queue
template <typename T>
void queuecin(queue<T> &q, int n) {
    for (int i = 0; i < n; i++) {
        T x;
        cin >> x;
        q.push(x);
    }
}

//priority_queue
template <typename T>
void queuecin(priority_queue<T> &q, int n) {
    for (int i = 0; i < n; i++) {
        T x;
        cin >> x;
        q.push(x);
    }
}

//stack
template <typename T>
void stackcin(stack<T> &s, int n) {
    for (int i = 0; i < n; i++) {
        T x;
        cin >> x;
        s.push(x);
    }
}

//組み合わせ
template< typename T >
struct Combination {
    vector< T > _fact, _rfact, _inv;
    Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
        _fact[0] = _rfact[sz] = _inv[0] = 1;
        for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
        _rfact[sz] /= _fact[sz];
        for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
        for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
    }
    inline T fact(int k) const { return _fact[k]; }
    inline T rfact(int k) const { return _rfact[k]; }
    inline T inv(int k) const { return _inv[k]; }
    T P(int n, int r) const {
        if(r < 0 || n < r) return 0;
        return fact(n) * rfact(n - r);
    }
    T C(int p, int q) const {
        if(q < 0 || p < q) return 0;
        return fact(p) * rfact(q) * rfact(p - q);
    }
    T H(int n, int r) const {
        if(n < 0 || r < 0) return (0);
        return r == 0 ? 1 : C(n + r - 1, r);
    }
};

template <typename T>
int64_t LIS (const vector<T>& V) {
    vector<T> DP(V.size());
    int len = 0;
    for (const auto& x : V) {
        auto itr = lower_bound(DP.begin(), DP.begin() + len, x);
        *itr = x;
        if (itr == DP.begin() + len) len++;
    }
    return len;
}

int64_t powmod(int64_t a, int64_t b, int64_t mod) {
    a %= mod;
    int64_t res = 1 % mod;
    while (b) {
        if (b&1) res = (res * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

template <typename T>
bool chtop(vector<T>& a, const T& b, int limit_size = -1) {
    if (limit_size == -1) limit_size = a.size();
    if ((int)a.size() < limit_size) {
        auto it = lower_bound(a.begin(), a.end(), b, greater<T>());
        a.insert(it, b);
        return true;
    }
    if (limit_size == 0 || b <= a.back()) return false;
    a.pop_back();
    auto it = lower_bound(a.begin(), a.end(), b, greater<T>());
    a.insert(it, b);
    return true;
}
template <typename T>
bool chbot(vector<T>& a, const T& b, int limit_size = -1) {
    if (limit_size == -1) limit_size = a.size();
    if ((int)a.size() < limit_size) {
        auto it = lower_bound(a.begin(), a.end(), b);
        a.insert(it, b);
        return true;
    }
    if (limit_size == 0 || b >= a.back()) return false;
    a.pop_back();
    auto it = lower_bound(a.begin(), a.end(), b);
    a.insert(it, b);
    return true;
}

//ループマクロ
#define     re(n)       for (int64_t r_= 0;            r_<  int64_t(n);r_++)
#define    rep(i, n)    for (int64_t i = 0;            i <  int64_t(n); i++)
#define   repp(i, n)    for (int64_t i = 0;            i <= int64_t(n); i++)
#define   rrep(i, a, b) for (int64_t i = int64_t(a);   i <  int64_t(b); i++)
#define  rrepp(i, a, b) for (int64_t i = int64_t(a);   i <= int64_t(b); i++)
#define   reep(i, n)    for (int64_t i = int64_t(n)-1; i >= 0;          i--)
#define  reepp(i, n)    for (int64_t i = int64_t(n);   i >= 0;          i--)
#define  rreep(i, a, b) for (int64_t i = int64_t(b)-1; i >= int64_t(a); i--)
#define rreepp(i, a, b) for (int64_t i = int64_t(b);   i >= int64_t(a); i--)
template<class T, class U> bool chmax(T& a, const U&b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T, class U> bool chmin(T& a, const U&b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

//セグ木
static constexpr int64_t seg_MOD = 998244353;
static constexpr int64_t seg_ID = -8'000'000'000'000'000'000LL;

constexpr int64_t sum_op (int64_t a, int64_t b) { return (a + b); }
constexpr int64_t mul_op (int64_t a, int64_t b) { return (a * b); }
constexpr int64_t SUM_op (int64_t a, int64_t b) { return (a + b) % seg_MOD; }
constexpr int64_t MUL_op (int64_t a, int64_t b) { return (a * b) % seg_MOD; }
          string  txt_op (string  a, string  b) { return (a + b); }
constexpr int64_t min_op (int64_t a, int64_t b) { return min(a , b); }
constexpr int64_t max_op (int64_t a, int64_t b) { return max(a , b); }
constexpr int64_t lcm_op (int64_t a, int64_t b) { return lcm(a , b); }
constexpr int64_t gcd_op (int64_t a, int64_t b) { return gcd(a , b); }
constexpr int64_t and_op (int64_t a, int64_t b) { return (a & b); }
constexpr int64_t or_op  (int64_t a, int64_t b) { return (a | b); }
constexpr int64_t xor_op (int64_t a, int64_t b) { return (a ^ b); }
constexpr pair<int64_t, int64_t> sum_OP (pair<int64_t, int64_t> a, pair<int64_t, int64_t> b)
    { return {sum_op(a.first, b.first), a.second + b.second}; }

constexpr int64_t no0_e () { return 0; }
constexpr int64_t no1_e () { return 1; }
constexpr int64_t all_e () { return -1; }
          string  emp_e () { return ""; }
constexpr int64_t max_e () { return  4'000'000'000'000'000'000LL; }
constexpr int64_t min_e () { return -4'000'000'000'000'000'000LL; }
constexpr pair<int64_t, int64_t> no0_E () { return {0, 0}; }

constexpr int64_t add_map (int64_t f, int64_t x) { return x + f; }
constexpr int64_t upd_map (int64_t f, int64_t x) { return f == seg_ID ? x : f; }
constexpr pair<int64_t, int64_t> add_MAP (int64_t f, pair<int64_t, int64_t> x) { x.first += f * x.second; return x; }
constexpr pair<int64_t, int64_t> upd_MAP (int64_t f, pair<int64_t, int64_t> x) { if (f != seg_ID) x.first = f * x.second; return x; }

constexpr int64_t add_com (int64_t f, int64_t g) { return g + f; }
constexpr int64_t upd_com (int64_t f, int64_t g) { return f == seg_ID ? g : f; }

constexpr int64_t no0_id () { return 0; }
constexpr int64_t upd_id () { return seg_ID; }

//セグ木
using sumtree = segtree<int64_t, sum_op, no0_e>;
using multree = segtree<int64_t, mul_op, no1_e>;
using txttree = segtree<string , txt_op, emp_e>;
using mintree = segtree<int64_t, min_op, max_e>;
using maxtree = segtree<int64_t, max_op, min_e>;
using lcmtree = segtree<int64_t, lcm_op, no1_e>;
using gcdtree = segtree<int64_t, gcd_op, no0_e>;
using andtree = segtree<int64_t, and_op, all_e>;
using ortree  = segtree<int64_t, or_op,  no0_e>;
using xortree = segtree<int64_t, xor_op, no0_e>;
using summodtree = segtree<int64_t, SUM_op, no0_e>;
using mulmodtree = segtree<int64_t, MUL_op, no1_e>;

//遅延セグ木
using lazyaddsum = lazy_segtree<pair<int64_t, int64_t>, sum_OP, no0_E, int64_t, add_MAP, add_com, no0_id>;
using lazyupdsum = lazy_segtree<pair<int64_t, int64_t>, sum_OP, no0_E, int64_t, upd_MAP, upd_com, upd_id>;
using addmintree = lazy_segtree<int64_t, min_op, max_e, int64_t, add_map, add_com, no0_id>;
using updmintree = lazy_segtree<int64_t, min_op, max_e, int64_t, upd_map, upd_com, upd_id>;
using addmaxtree = lazy_segtree<int64_t, max_op, min_e, int64_t, add_map, add_com, no0_id>;
using updmaxtree = lazy_segtree<int64_t, max_op, min_e, int64_t, upd_map, upd_com, upd_id>;

struct addsumtree : lazyaddsum {
    addsumtree (int64_t n) : lazyaddsum(vector<pair<int64_t, int64_t>>(n, {0, 1})) {}
    addsumtree (vector<int64_t> v) : lazyaddsum([&]{
        vector<pair<int64_t, int64_t>> p(v.size());
        for (int64_t i = 0; i < (int64_t)v.size(); i++) p[i] = {v[i], 1};
        return p;
    }()) {}
    int64_t get(int p) { return lazyaddsum::get(p).first; }
    int64_t prod(int l, int r) { return lazyaddsum::prod(l, r).first; }
    int64_t all_prod() { return lazyaddsum::all_prod().first; }
};
struct updsumtree : lazyupdsum {
    updsumtree (int64_t n) : lazyupdsum(vector<pair<int64_t, int64_t>>(n, {0, 1})) {}
    updsumtree (vector<int64_t> v) : lazyupdsum([&]{
        vector<pair<int64_t, int64_t>> p(v.size());
        for (int64_t i = 0; i < (int64_t)v.size(); i++) p[i] = {v[i], 1};
        return p;
    }()) {}
    int64_t get(int p) { return lazyupdsum::get(p).first; }
    int64_t prod(int l, int r) { return lazyupdsum::prod(l, r).first; }
    int64_t all_prod() { return lazyupdsum::all_prod().first; }
};

using lint = int64_t;
using pll = pair<int64_t, int64_t>;
using tll = tuple<int64_t, int64_t, int64_t>;
using vl = vector<lint>;
using vvl = vector<vector<lint>>;
using vvvl = vector<vector<vector<lint>>>;
using vpll = vector<pair<lint,lint>>;
using ld = long double;
using mint = modint998244353;
void yn(bool b) { cout << (b ? "Yes" : "No") << endl; }
const lint MOD = 998244353;
// const lint MOD = 1000000007;
const lint INF = 4004004004004004004;
const ld pi = 3.141592653589793238;
const lint dx[] = {-1,0,1,0,-1,1,1,-1};
const lint dy[] = {0,-1,0,1,-1,-1,1,1};


void solve() {
    lint n, m, k; cin >> n >> m >> k;
    if (n*n%m||k*k<m){
        cout << "-1\n";
        return;
    }
    vvl ans(n,vl(n,-1)), tmp(k, vl(k,-1));
    rep(i,m)tmp[i/k][i%k]=i+1;
    rep(i,n)rep(j,n){
        ans[i][j]=tmp[i%k][j%k];
    }
    lint now = 0;
    rep(i,n)rep(j,n){
        if(ans[i][j]!=-1)continue;
        ans[i][j] = (now++)%m+1;
    }
    cout<<ans<<"\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(20);
    int T = 1;
    // cin >> T;
    while (T--) solve();
}
0