結果

問題 No.3733 My First Grid
コンテスト
ユーザー Katu2ou
提出日時 2026-09-19 16:14:12
言語 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  
実行時間 -
コード長 10,964 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,977 ms
コンパイル使用メモリ 384,340 KB
実行使用メモリ 13,184 KB
最終ジャッジ日時 2026-09-19 16:14:50
合計ジャッジ時間 8,083 ms
ジャッジサーバーID
(参考情報)
judge4_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 54 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define all(...) std::begin(__VA_ARGS__), std::end(__VA_ARGS__)
#define rall(...) std::rbegin(__VA_ARGS__), std::rend(__VA_ARGS__)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (long long)1001001001001001001
#define inf 1001001000
#define MOD 998244353
#define MOD1 1000000007
#define PI 3.14159265358979
#define epsilon 1e-12
#define fcout cout << fixed << setprecision(12)
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<long long>;
using vs = vector<string>;
using vd = vector<double>;
using vld = vector<long double>;
using vb = vector<bool>;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<long long, long long>>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvd = vector<vector<double>>;
using vvld = vector<vector<long double>>;
using vvb = vector<vector<bool>>;
using vvpii = vector<vector<pair<int,int>>>;
using vvpll = vector<vector<pair<long long,long long>>>;
using vvvi = vector<vector<vector<int>>>;
using vvvl = vector<vector<vector<long long>>>;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using LL = __int128_t;
using mint = atcoder::modint998244353;
using vmint = vector<mint>;
using vvmint = vector<vector<mint>>;
using vvvmint = vector<vector<vector<mint>>>;

ll gcd(ll x, ll y) {x = abs(x); y = abs(y); if (x == 0) return y;	return gcd(y%x, x);} 
ll lcm(ll x, ll y) { __int128_t xx,yy; xx=x; yy=y; __int128_t ans=xx * yy / gcd(x, y); ll ans2=ans; return ans2; }
template<typename T>
T POW(T x, ll n){T ret=1;	while(n>0){		if(n&1) ret=ret*x;		x=x*x;		n>>=1;	}	return ret;}
template<typename T>
T modpow(T a, ll n, T p) {	if(n==0) return (T)1;  if (n == 1) return a % p;  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;  T t = modpow(a, n / 2, p);  return (t * t) % p;}
template<typename T>
T modinv(T a, T m) {	if(m==0)return (T)1;	T b = m, u = 1, v = 0;	while (b) {		T t = a / b;		a -= t * b; swap(a, b);		u -= t * v; swap(u, v);	}	u %= m;	if (u < 0) u += m;	return u;}
ll REM(ll a, ll b){ return (a % b + b) % b;}
ll QUO(ll a, ll b){ return (a - REM(a, b)) / b;}
/*
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> dist1(1, 100); [1,100]
int random_value = dist1(gen);
*/
/*
auto start = chrono::steady_clock::now(); //時間計測の開始
auto now = std::chrono::steady_clock::now(); //現在時刻と開始時刻の差を測定
double elapsed = std::chrono::duration<double>(now - start).count(); //時間をdouble型で取得
*/
/*
const int MAXCOMB=510000;
std::vector<mint> FAC(MAXCOMB), FINV(MAXCOMB), INV(MAXCOMB);
void COMinit() {FAC[0] = FAC[1] = 1;FINV[0] = FINV[1] = 1;INV[1] = 1;for (int i = 2; i < MAXCOMB; i++) {FAC[i] = FAC[i - 1] * i;INV[i] = mint(0) - INV[mint::mod() % i] * (mint::mod() / i);FINV[i] = FINV[i - 1] * INV[i];}}
mint COM(int n, int k) {if (n < k) return 0;if (n < 0 || k < 0) return 0;return FAC[n] * FINV[k] * FINV[n - k];}
*/

template <typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false));}
template <typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false));}
template <class T> T BS(vector<T> &vec, T key) {return lower_bound(vec.begin(), vec.end(), key) - vec.begin();}
template<class T> pair<T,T> RangeBS(vector<T> &vec, T lowv, T highv){auto itr_l = lower_bound(vec.begin(), vec.end(), lowv); auto itr_r = upper_bound(vec.begin(), vec.end(), highv); return make_pair(distance(vec.begin(), itr_l), distance(vec.begin(), itr_r)-1);}
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); } void yes() { cout << "Yes\n"; exit(0); }
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1};
bool range_in(int i, int j, int h, int w){ if(i<0 || j<0 || i>=h || j>=w) return false; return true;} 
int bitcount(int n){n=(n&0x55555555)+(n>>1&0x55555555); n=(n&0x33333333)+(n>>2&0x33333333); n=(n&0x0f0f0f0f)+(n>>4&0x0f0f0f0f); n=(n&0x00ff00ff)+(n>>8&0x00ff00ff); n=(n&0x0000ffff)+(n>>16&0x0000ffff); return n;}

template<typename T>
struct Edge{
    int from, to, index;
    T cost;
    Edge() : from(-1), to(-1), index(-1), cost(0) {}
    Edge(int _to) : from(-1), to(_to), index(-1), cost(0) {}
    Edge(int _to, T _cost) : from(-1), to(_to), index(-1), cost(_cost) {}
    Edge(int _from, int _to, int _index) : from(_from), to(_to), index(_index), cost(0) {}
    Edge(int _from, int _to, int _index, T _cost) 
        : from(_from), to(_to), index(_index), cost(_cost) {}
    bool operator<(const Edge<T>& other) const {
        return cost < other.cost; 
    }
    Edge &operator=(const int &x) {
        to = x;
        return *this;
    }
    operator int() const { return to; }
};
using Graph = vector<vector<int>>; 
template <typename T>
using WGraph = vector<vector<Edge<T>>>; 

/////////////////////////////////////////////////////////////////////////////////////////


void solve(){
    int h, w, k;
    cin >> h >> w >> k;
    int K = k;
    int swapped = 0;
    if (k == 0) {
        rep(i,h){
            rep(j, w) cout << ".";
            cout << endl;
        }
        return;
     }
    if (w < h) {
        swap(h, w);
        swapped = 1;
    }
    vs gr(h);
    rep(i, h) rep(j, w) gr[i] += '.';
   
    if(h==1){
        if(k>=2){
            cout << -1 << endl;
        }
        if(k==1){
            gr[0][0] = '#';
        }
        
        if(swapped){
            rep(j,w){
                rep(i,h){
                    cout << gr[i][j];
                }
                cout << endl;
            }
        }
        else{
            rep(i,h){
                rep(j,w){
                    cout << gr[i][j];
                }
                cout << endl;
            }
        }
        return;
    }
    if(k==1){
        cout << -1 << endl;
        return;
    }

    if((h-1)*(w-1)+1<k){

        cout << -1 << endl;
        return;
    }
    if(h==2){
        for (int i = 0; i < k - 1;i++){
            gr[0][i] = '#';
        }
         if(swapped){
            rep(j,w){
                rep(i,h){
                    cout << gr[i][j];
                }
                cout << endl;
            }
        }
        else{
            rep(i,h){
                rep(j,w){
                    cout << gr[i][j];
                }
                cout << endl;
            }
        }
        return;
    }

    vvi down(h + 1, vi(w + 1));
    vvi right(h + 1, vi(w + 1));
    

    // if(k==2){
    //     down[0][1] = 1;
    //     right[1][0] = 0;
    // }

    int x = 1;
    int y = 1;

    int dir = 0;//0なら下
    k -= 1;
    down[0][1]=1;
    for (int j = 1; j <= w; j++) {
        //cout << j << " " << k << endl;
        if(k==0)
            break;
        if (k == 1) {
            if(j==1)
                {right[1][0] = 1;
                k--;
                break;
            }
            if(x==1){
                down[0][j-1] = 1;
                k--;
                break;
            } else if (y == w - 1) {
                right[x][y] = 1;
                k--;
                break;
            } else {
                down[h-1][j-1] = 1;
                k--;
                break;
            }
        }
        if(j>=2){
            right[x][j-1] = 1;
            k--;
            y++;
            if(k==1)
                break;
        }

        //進む
        int nxt = 0;
        int fin = 0;
        if (x == 1) {
            for (int i = 1; i <= h - 2; i++) {
                down[i][j] = 1;
                k--;
                x++;
                if(k==1){
                    if(j==1){
                        fin = 1;
                        right[x][0] = 1;
                        break;
                    }
                    nxt = 1;
                    break;
                }

            }
        } else {
            for (int i = h - 2; i >= 1;i--){
                down[i][j] = 1;
                k--;
                x--;
                if(k==1){
                    nxt = 1;
                    break;
                }
           
            }
        }

        //cout << nxt << endl;
        if (fin)
            break;
           if(nxt)
            continue;

        //右に進むかどうかの判定

        //cout << k << " " << j << endl;
        if (k <= h-1) {
            //右までいって調整
            while(y<w-1){
                if(k==1)
                    break;
                right[x][y]=1;
                y++;
                k--;
            }
            if(k==1){
                if(x==1)down[0][y] = 1;
                else if(x==h-1)
                    down[h - 1][y] = 1;
                k--;
                break;
            }
            while(x<h-1){
                if(k==1)
                    break;
                down[x][y] = 1;
                x++;
                k--;
            }
            while(x>1){
                if(k==1)
                    break;
                down[x-1][y] = 1;
                x--;
                k--;
            }
            if(k==1){
                right[x][y] = 1;
                k--;
                break;
            }
        }
    }
    
    // if(k){
    //     for (int i = y; i <= w - 2;i++){

    //     }
    // }
    int now = 0;
    int cnt = 0;
    for (int i = 1; i < w; i++) {
        if(down[0][i]==1)
            {now ^= 1;
            cnt++;}
            if (now) {
                gr[0][i] = '#';
            }
    }
    now = 0;
    for (int j = 1; j < h; j++) {
        if(right[j][0]==1)
           { now ^= 1;
            cnt++;}
            if (now)
                gr[j][0] = '#';
    }
    for (int i = 1; i < h;i++){
        if(gr[i][0]=='.')
            now = 0;
        else
            now = 1;
        for (int j = 1; j < w; j++) {
            if(down[i][j]==1)
                {now ^= 1;
                cnt++;}
                if (now)
                    gr[i][j] = '#';
        }
    }
    if(swapped==1){
        if(swapped){
            rep(j,w){
                rep(i,h){
                    cout << gr[i][j];
                }
                cout << endl;
            }
        }
    }
    else{
        rep(i,h){
            rep(j,w){
                cout << gr[i][j];
            }
            cout << endl;
        }
    }

    // if(cnt!=K){
    //     cout << h << " " << w << " " << endl;
    // }
}

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