結果
| 問題 |
No.3335 ReCT
|
| コンテスト | |
| ユーザー |
こめだわら
|
| 提出日時 | 2025-11-07 22:45:05 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 6,807 bytes |
| コンパイル時間 | 3,768 ms |
| コンパイル使用メモリ | 303,572 KB |
| 実行使用メモリ | 17,536 KB |
| 最終ジャッジ日時 | 2025-11-07 22:45:15 |
| 合計ジャッジ時間 | 9,916 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 93 WA * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define all(a) (a).begin(),(a).end()
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
template<class T> T div_floor(T a, T b) { return a / b - ((a ^ b) < 0 && a % b); }
template<class T> T div_ceil(T a, T b) { return a / b + ((a ^ b) > 0 && a % b); }
template <typename T, typename U> inline bool chmin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template <typename T, typename U> inline bool chmax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a){
if (a.empty()) return os;
os << a.front();
for (auto e : a | views::drop(1)){
os << ' ' << e;
}
return os;
}
void dump(auto ...vs){
((cout << vs << ' '), ...) << endl;
}
vector<vector<ll>> trans(vector<vector<ll>> A,bool t){
if (!t){
return A;
}
ll H=A.size();
ll W=A[0].size();
vector<vector<ll>> B(W,vector<ll> (H));
rep(i,H){
rep(j,W){
B[j][i]=A[i][j];
}
}
return B;
}
vector<vector<ll>> solveC(ll H,ll W){
bool swapped=false;
if (H>W){
swap(H,W);
swapped=true;
}
if (H==2)return {};
if (H==3){
if (W%4!=0)return {};
vector<vector<ll>> R(H,vector<ll> (W,0));
vector<vector<ll>> base={{0,1,1,1},{0,1,0,1},{0,0,0,1}};
rep(bj,W/4){
rep(i,3){
rep(j,4){
R[i][bj*4+j]=base[i][j]+bj*2;
}
}
}
return trans(R,swapped);
}
if (H==4){
vector<vector<ll>> R(H,vector<ll> (W,0));
rep(j,W){
if (j==0){
continue;
}
R[1][j]=1;
}
R[2][W-1]=1;
rep(j,W){
R[3][j]=1;
}
return trans(R,swapped);
}
if (H==5){
vector<vector<ll>> R(H,vector<ll> (W,0));
vector<ll> line0={0,0,1,1,1};
vector<ll> line1={0,2,2,2,1};
vector<ll> line2={0,0,0,0,0};
vector<ll> linen={0,2,1,2,1};
rep(i,5){
R[i][0]=line0[i];
}
rep(i,5){
R[i][W-2]=line1[i];
}
rep(i,5){
R[i][W-1]=line2[i];
}
for (ll j=1;j<W-2;j++){
rep(i,5){
R[i][j]=linen[i];
}
}
return trans(R,swapped);
}
vector<vector<ll>> R(H,vector<ll> (W,0));
vector<vector<ll>> I=solveC(H-2,W-1);
rep(i,H-2){
rep(j,W-1){
R[i+1][j+1]=I[i][j]+1;
}
}
return trans(R,swapped);
}
vector<vector<ll>> solveT(ll H,ll W){
bool swapped=false;
if (H>W){
swap(H,W);
swapped=true;
}
if (H==2)return {};
if (H==3){
if (W<=5)return {};
vector<vector<ll>> R(H,vector<ll> (W,0));
vector<vector<ll>> base={{0,1,1,1},{0,0,1,2},{0,2,2,2}};
rep(i,3){
rep(j,4){
R[i][j]=base[i][j];
}
}
for (ll j=4;j<W-1;j++){
R[0][j]=1;
R[1][j]=3;
R[2][j]=2;
}
R[0][W-1]=3;
R[1][W-1]=3;
R[2][W-1]=3;
return trans(R,swapped);
}
if (H==4){
vector<vector<ll>> R(H,vector<ll> (W,0));
vector<vector<ll>> basel={{0,2},{0,0},{0,1},{1,1}};
vector<vector<ll>> baser={{2,2},{2,3},{3,3},{1,3}};
rep(i,4){
rep(j,2){
R[i][j]=basel[i][j];
}
}
rep(i,4){
rep(j,2){
R[i][W-2+j]=baser[i][j];
}
}
for (ll j=2;j<W-2;j++){
R[0][j]=2;
R[1][j]=0;
R[2][j]=3;
R[3][j]=1;
}
return trans(R,swapped);
}
if (H==5){
vector<vector<ll>> R(H,vector<ll> (W,0));
vector<vector<ll>> basel={{0,0},{2,0},{2,2},{2,1},{1,1}};
vector<vector<ll>> baser={{0,3},{3,3},{4,3},{4,4},{1,1}};
rep(i,5){
rep(j,2){
R[i][j]=basel[i][j];
}
}
rep(i,5){
rep(j,2){
R[i][W-2+j]=baser[i][j];
}
}
for (ll j=2;j<W-2;j++){
R[0][j]=0;
R[1][j]=3;
R[2][j]=2;
R[3][j]=4;
R[4][j]=1;
}
return trans(R,swapped);
}
vector<vector<ll>> R(H,vector<ll> (W,0));
vector<vector<ll>> base={{0,0},{1,0},{1,1}};
rep(i,3){
rep(j,2){
R[i][j]=base[i][j];
}
}
for (ll i=3;i<H-1;i++){
R[i][0]=1;
R[i][1]=2;
}
rep(j,W){
R[0][j]=0;
R[H-1][j]=2;
}
vector<vector<ll>> I=solveT(H-2,W-2);
rep(i,H-2){
rep(j,W-2){
R[i+1][j+2]=I[i][j]+3;
}
}
return trans(R,swapped);
}
vector<vector<ll>> solveCT(ll H,ll W){
bool swapped=false;
if (H>W){
swap(H,W);
swapped=true;
}
if (H==2)return {};
if (H==3){
vector<vector<ll>> R(H,vector<ll> (W,0));
for (ll j=1;j<W-1;j++){
R[1][j]=1;
}
R[0][W-1]=1;
R[1][W-1]=1;
R[2][W-1]=1;
return trans(R,swapped);
}
if (H==4){
vector<vector<ll>> R(H,vector<ll> (W,0));
vector<vector<ll>> baser={{0,2},{2,2},{1,2},{1,1}};
R[3][0]=1;
rep(i,4){
rep(j,2){
R[i][W-2+j]=baser[i][j];
}
}
for (ll j=1;j<W-2;j++){
R[1][j]=2;
R[3][j]=1;
}
return trans(R,swapped);
}
vector<vector<ll>> R(H,vector<ll> (W,0));
vector<vector<ll>> I=solveCT(H-2,W-1);
rep(i,H-2){
rep(j,W-1){
R[i+1][j+1]=I[i][j]+1;
}
}
return trans(R,swapped);
}
void output(vector<vector<ll>> A){
ll H=A.size();
if (H==0){
cout<<-1<<'\n';
return;
}
ll W=A[0].size();
ll m=0;
rep(i,H){
rep(j,W){
A[i][j]++;
chmax(m,A[i][j]);
}
}
cout<<m<<'\n';
rep(i,H){
rep(j,W){
cout<<A[i][j]<<' ';
}
cout<<'\n';
}
return;
}
void solve() {
ll H,W;
cin>>H>>W;
vector<vector<ll>> res;
res=solveC(H,W);
output(res);
res=solveT(H,W);
output(res);
res=solveCT(H,W);
output(res);
return;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
ll T=1;
while (T--){
solve();
}
return 0;
}
こめだわら