結果

問題 No.1434 Make Maze
ユーザー queeequeee
提出日時 2021-03-19 22:58:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 4,015 bytes
コンパイル時間 982 ms
コンパイル使用メモリ 106,060 KB
実行使用メモリ 5,240 KB
最終ジャッジ日時 2023-08-16 09:25:31
合計ジャッジ時間 6,386 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 11 ms
5,096 KB
testcase_03 AC 11 ms
5,240 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 5 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 7 ms
4,380 KB
testcase_25 AC 12 ms
4,504 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 5 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 3 ms
4,380 KB
testcase_31 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // 
#include <vector> //
#include <algorithm> // 
#include <queue> // 
#include <string> // 
#include <functional> // 
#include <set> // 
#include <unordered_map> // 
#include <random> // 
#include <ctime> // 
#include <bitset> // 
#include <cassert>

// #include <atcoder/all>
// using namespace atcoder;
// g++ t.cpp -o t -I .

#define DB cerr<<"D"<<endl

struct _zo{_zo(){std::cin.tie(nullptr);std::cout.tie(nullptr);std::ios::sync_with_stdio(false);}}__zo;
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
using P=pair<ll,ll>;
using Q=pair<pair<ll,ll>,ll>;
const ll M = 998244353;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
ll mod_pow(ll x, ll a, ll m) { ll an = 1; while(a > 0) { if (a&1) an = an * x % m; x = x * x % m; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;} bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
ll gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};


int main() {
  int h,w,x;cin>>h>>w>>x;
  if(x%2){
    cout<<-1<<endl;
    return 0;
  }
  h++;w++;h/=2;w/=2;x/=2;
  if(x<w-1) {
    cout<<-1<<endl;
    return 0;
  }

  int g = h-1+w-1;
  if (g%2 != x%2) {
    cout<<-1<<endl;
    return 0;
  }

  //cout<<h<<" "<<w<<" "<<x<<endl;

  bool u = false;
  if (h%2) {
    u=true; swap(w,h);
  }

  // 横が奇数ならうねうね
  if(w%2) {
    x-=g; // 右上通過最短
    if(x<0){cout<<-1<<endl;return 0;}
    int a[w]={};
    for(int i=0;i<w-2;i+=2) {
      if(x==0)break;
      for(int j=1;j<h;j++) {
        a[i]++; x-=2;
        if(x==0)break;
      }
      if(x==0)break;
    }
    //for(int i=0;i<w;i++){cout<<a[i]<<" ";}cout<<endl;
    //cout<<x<<endl;
    if(x>0){
      cout<<-1<<endl;
      return 0;
    }
    string s[2*h-1];
    for(int i=0;i<2*h-1;i++) {
      for(int j=0;j<2*w-1;j++) {
        if (i%2==0||j==2*w-2)s[i]+='.';
        else s[i]+='#';
      }
    }
    for(int i=0;i<w;i+=2) {
      for(int j=0;j<a[i];j++) {
        s[2*j][2*i+1] = '#';
        s[2*j+1][2*i] = '.';
        s[2*j+2][2*i+3] = '#';
        s[2*j+1][2*i+2] = '.';
      }
    }
    if (!u) {
      for(int i=0;i<2*h-1;i++) {
        cout<<s[i]<<endl;
      }
    } else {
      for(int i=0;i<2*w-1;i++) {
        for(int j=0;j<2*h-1;j++) {
          cout<<s[j][i];
        }cout<<endl;
      }
    }
    return 0;
  }

  x-=g; // 右上通過最短
  if(x<0){cout<<-1<<endl;return 0;}
  int a[w]={};
  for(int i=0;i<w;i+=2) {
    if(x==0)break;
    for(int j=1;j<h;j++) {
      if(i+2>=w && j > (h-1)/2) break;
      a[i]++; x-=2;
      if(x==0)break;
    }
    if(x==0)break;
  }
  //for(int i=0;i<w;i++){cout<<a[i]<<" ";}cout<<endl;
  //cout<<x<<endl;
  if(x>0){
    cout<<-1<<endl;
    return 0;
  }
  string s[2*h-1];
  for(int i=0;i<2*h-1;i++) {
    for(int j=0;j<2*w-1;j++) {
      if (i%2==0||j==2*w-2)s[i]+='.';
      else s[i]+='#';
    }
  }
  for(int i=0;i<w;i+=2) {
    if(i+2>=w){
      for(int j=0;j<a[i];j++) {
        s[3+4*j][2*w-2] = '#';
        s[3+4*j][2*w-4] = '.';
      }
    }else{
      for(int j=0;j<a[i];j++) {
        s[2*j][2*i+1] = '#';
        s[2*j+1][2*i] = '.';
        s[2*j+2][2*i+3] = '#';
        s[2*j+1][2*i+2] = '.';
      }
    }
  }
  for(int i=0;i<2*h-1;i++) {
    cout<<s[i]<<endl;
  }
}
// 

// ・配列の大きさok? ・priority_queueはgreater? ・debug消した?
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest
0