結果

問題 No.3734 No Flat Notes
コンテスト
ユーザー caz37OwO
提出日時 2026-10-08 09:24:47
言語 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  
実行時間 -
コード長 4,205 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,185 ms
コンパイル使用メモリ 392,492 KB
実行使用メモリ 9,908 KB
最終ジャッジ日時 2026-10-08 09:25:01
合計ジャッジ時間 13,151 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
サブタスク 配点 結果
部分点 20 % AC * 28
満点 80 % AC * 58 WA * 2
合計 3.5 * 20% = 70 点
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'tup2<long long int> grid_move(ll, ll, ll)':
main.cpp:93:1: warning: control reaches end of non-void function [-Wreturn-type]
   93 | }
      | ^

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using ll=long long;
using ldub=long double;
using lldub=__float128;
using str=string;

using mint=modint;

template<class T=ll>
using tup2=tuple<T,T>;
template<class T=ll>
using tup3=tuple<T,T,T>;
template<class T=ll>
using tup4=tuple<T,T,T,T>;
template<class T=ll>
using tup5=tuple<T,T,T,T,T>;
template<class T=ll>
using tup6=tuple<T,T,T,T,T,T>;
template<class T=ll>
using tup7=tuple<T,T,T,T,T,T,T>;

template<class T=ll>
using vec=vector<T>;
template<class T=ll>
using vec2=vector<vec<T>>;
template<class T=ll>
using vec3=vector<vec2<T>>;
template<class T=ll>
using vec4=vector<vec3<T>>;
template<class T=ll>
using vec5=vector<vec4<T>>;
template<class T=ll>
using vec6=vector<vec5<T>>;

template<class T>
using que=queue<T>;
template<class T>
using Pque=priority_queue<T>;
template<class T>
using pque=priority_queue<T, vector<T>, greater<T>>;

struct Edge{
  ll from,to,w=1,num=-1;
};
using gvec=vector<Edge>;
using gvec2=vector<gvec>;

template<class T>
bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define ins insert
#define tup make_tuple
#define low lower_bound
#define pops(a) __builtin_popcountll(a)
#define ctz(a) __builtin_ctzll(a)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define nperm(v) next_permutation(all(v))
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YN(f) cout << ((f)?"Yes":"No") << endl

const int IINF=2e9;
const ll INF=4e18;

#ifndef LOCAL
#define debug(x)
#endif




// =================================================




tup2<ll> grid_move(ll h,ll w,ll k){
  if(k==0) return tup2(h+1,w);
  if(k==1) return tup2(h,w+1);
  if(k==2) return tup2(h-1,w);
  if(k==3) return tup2(h,w-1);
}
ll out(ll h,ll w,ll H,ll W){return h<0||H<=h||w<0||W<=w;}

void solve(){
  ll H,W,K;
  cin >> H >> W >> K;
  K*=2;
  if(K==0||K==H*W-1){
    cout << -1 << endl;
    return;
  }
  if(H==1||W==1){
    ll l=0,r=H*W-1;
    vec2 A(H,vec(W,-1));
    for(ll i=0;i<H;i++){
      for(ll j=0;j<W;j++){
        if(K==1) continue;
        if(((i+j)&1)==0) A[i][j]=l,l++;
        else A[i][j]=r,r--;
        K--;
      }
    }
    for(ll i=0;i<H;i++){
      for(ll j=0;j<W;j++){
        if(A[i][j]!=-1) continue;
        A[i][j]=l,l++;
      }
    }
    for(ll i=0;i<H;i++){
      for(ll j=0;j<W;j++) cout << A[i][j]+1 << ' ';
      cout << endl;
    }
    return;
  }
  vec2 D(H,vec(W));
  if((H&1)==0){
    for(ll i=0;i<H-1;i++) D[i][0]=0;
    D[H-1][0]=1;
    for(ll i=0;i<H;i++){
      for(ll j=1;j<W;j++){
        if((i&1)==0) D[i][j]=3;
        if((i&1)==1) D[i][j]=1;
      }
    }
    for(ll i=1;i<H;i++){
      if((i&1)==0) D[i][1]=2;
      if((i&1)==1) D[i][W-1]=2;
    }
  }else if((W&1)==0){
    for(ll i=0;i<W-1;i++) D[0][i]=1;
    D[0][W-1]=0;
    for(ll i=1;i<H;i++){
      for(ll j=0;j<W;j++){
        if((j&1)==0) D[i][j]=2;
        if((j&1)==1) D[i][j]=0;
      }
    }
    for(ll j=1;j<W;j++){
      if((j&1)==0) D[1][j]=3;
      if((j&1)==1) D[H-1][j]=3;
    }
  }else{
    for(ll i=0;i<H-1;i++) D[i][0]=0;
    D[H-1][0]=1;
    for(ll i=2;i<H;i++){
      for(ll j=1;j<W;j++){
        if((i&1)==0) D[i][j]=1;
        if((i&1)==1) D[i][j]=3;
      }
    }
    for(ll i=2;i<H;i++){
      if((i&1)==0) D[i][W-1]=2;
      if((i&1)==1) D[i][1]=2;
    }
    for(ll j=1;j<W;j+=2){
      D[0][j]=0,D[0][j+1]=3;
      D[1][j]=3,D[1][j+1]=2;
    }
  }
  ll l=0,r=H*W-1;
  vec2 A(H,vec(W,-1));
  {
    ll h=0,w=0,f=0;
    while(K){
      if(f==0) A[h][w]=l,l++;
      if(f==1) A[h][w]=r,r--;
      f^=1,K--;
      tie(h,w)=grid_move(h,w,D[h][w]);
    }
    while(A[h][w]==-1){
      A[h][w]=r,r--;
      tie(h,w)=grid_move(h,w,D[h][w]);
    }
  }
  if((H&1)==1&&(W&1)==1) swap(A[0][1],A[1][1]);
  for(ll i=0;i<H;i++){
    for(ll j=0;j<W;j++) cout << A[i][j]+1 << ' ';
    cout << endl;
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  mint::set_mod(998244353);
  // mint::set_mod(1000000007);

  ll T=1;
  // cin >> T;
  while(T--) solve();
  return 0;
}
0