結果

問題 No.3733 My First Grid
コンテスト
ユーザー karinohito
提出日時 2026-09-19 16:27:18
言語 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
結果
RE  
実行時間 -
コード長 1,612 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,482 ms
コンパイル使用メモリ 343,064 KB
実行使用メモリ 14,140 KB
最終ジャッジ日時 2026-09-19 16:27:30
合計ジャッジ時間 6,053 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 52 RE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using ll=long long;


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

    ll H,W,K;
    cin>>H>>W>>K;
    if(K==0){
        for(int h=0;h<H;h++){
            cout<<string(W,'.')<<"\n";
        }
        return 0;
    }
    if(H==1||W==1){
        if(K==1){
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    cout<<(i+j==0?'#':'.');
                }
                cout<<"\n";
            }
            return 0;
        }
    }
    if(K<2){
        cout<<-1<<"\n";
        return 0;
    }
    if(K>H*W-H-W+2){
        cout<<-1<<"\n";
        return 0;
    }
    if(K<=W){
        for(int i=0;i<W;i++){
            cout<<(i<K-1?'#':'.');
        }
        cout<<"\n";
        for(int i=0;i<H-1;i++){
            cout<<string(W,'.')<<"\n";;
        }
        return 0;
    }
    vector<string> S(H,string(W,'#'));
    vector<array<ll,2>> P,Q; 
    for(int j=1;j<W;j+=2){
        for(int i=1;i<H;i++){
            S[i][j]='.';
        }
    }
    for(int j=0;j<W;j+=2){
        for(int i=H-2;i>0;i--){
            if(j==0||j==W-1)P.push_back({i,j});
            else Q.push_back({i,j});
        }
    }
    for(int j=0;j<W;j++)S[H-1][j]='.';

    ll U=H*W-H-W+2;
    reverse(P.begin(),P.end());
    reverse(Q.begin(),Q.end());
    while(U>K+1){
        auto [y,x]=Q.back();
        S[y][x]='.';
        Q.pop_back();
        U-=2;
    }
    while(U>K){
        auto [y,x]=P.back();
        S[y][x]='.';
        P.pop_back();
        U-=1;
    }


    for(int i=0;i<H;i++){
        cout<<S[i]<<"\n";
    }
}
0