結果

問題 No.1974 2x2 Flipper
コンテスト
ユーザー eQe
提出日時 2025-12-25 00:18:42
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 3,898 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,508 ms
コンパイル使用メモリ 288,116 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-25 00:25:32
合計ジャッジ時間 6,985 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#if __has_include(<atcoder/all>)
#endif
using namespace std;
#define done(...) return pp(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__)
#define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a)
#define maybe(p,c) (p?c:remove_cvref_t<decltype(c)>{})
#define defpp template<ostream&o=cout>void pp(const auto&...a){[[maybe_unused]]const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}void epp(const auto&...a){pp<cerr>(a...);}
#define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{
namespace my{
void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
using ll=long long;
template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};}
template<class T>constexpr auto for_range(T s,T a,T b,T c=1){return array{a-s,b,(1-s*2)*c};}
const string newline{char(10)};
const string space{char(32)};
void lin(auto&...a){(cin>>...>>a);}
template<class A,class B=A>struct pair{
  A a;B b;
  pair()=default;
  pair(A a,B b):a(a),b(b){}
  auto operator<=>(const pair&)const=default;
};
template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;
}
namespace my{
template<class V>concept vectorial=is_base_of_v<vector<typename remove_cvref_t<V>::value_type>,remove_cvref_t<V>>;
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){ll n=v.size();fo(i,n)o<<v[i]<<maybe(i<n-1,space);return o;}
template<vectorial V>ostream&operator<<(ostream&o,const vector<V>&v){ll n=v.size();fo(i,n)o<<v[i]<<maybe(i<n-1,newline);return o;}
template<class V>constexpr int depth=0;
template<vectorial V>constexpr int depth<V> =depth<typename V::value_type>+1;
template<class T>struct core_t_helper{using type=T;};
template<vectorial V>struct core_t_helper<V>{using type=typename core_t_helper<typename V::value_type>::type;};
template<class T>using core_t=core_t_helper<T>::type;
template<class V>struct vec;
template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;};
template<class T>struct hvec_helper<0,T>{using type=T;};
template<int D,class T>using hvec=hvec_helper<D,T>::type;
template<class V>struct vec:vector<V>{
  static constexpr int D=depth<V>+1;
  using C=core_t<V>;
  using vector<V>::vector;
  vec(const auto&...a)requires(sizeof...(a)>=3){resizes(a...);}
  void resizes(const auto&...a){if constexpr(sizeof...(a)==D){ }else*this=make(a...);}
  static auto make(ll n,const auto&...a){
    if constexpr(sizeof...(a)==1)return vec<C>(n,array{a...}[0]);
    else return vec<decltype(make(a...))>(n,make(a...));
  }
  ll size()const{return vector<V>::size();}
  template<class T=C>auto fold(auto&&f)const{
    pair<T,bool>res{};
    fe(*this,e){
      if constexpr(!vectorial<V>){
        if(res.b)f(res.a,e);
        else res={e,1};
      }else if(auto t=e.fold(f);t.b){
        if(res.b)f(res.a,t.a);
        else res=t;
      }
    }
    return res;
  }
  template<class T=C>auto sum()const{return fold<T>([](auto&a,const auto&b){a+=b;}).a;}
  inline ll row()const{return size();}
  inline ll col()const{return (*this)[0].size();}
  auto transpose()const{
    assert(col());
    vec r(col());
    fe(r,e)e.resize(row());
    fo(i,row())fo(j,col())r[j][i]=(*this)[i][j];
    return r;
  }
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
}
namespace my{entry
void main(){
  LL(H,W);
  if(H==1||W==1){
    pp(0);
    done(vec(H,W,0));
  }
  vec a(H,W,1);

  if(H%2==0){
    if(W%2==0);
    else fo(i,H)a[i][W-1]=0;
  }
  else{
    if(W%2==0)fo(j,W)a[H-1][j]=0;
    else{
      bool sw=0;
      if(H>W)sw=1,swap(H,W),a=a.transpose();
      fo(i,H)a[i][i]=0;
      fo(j,H,W)a[H-1][j]=0;
      if(sw)a=a.transpose();
    }
  }
  pp(a.sum());
  pp(a);
}}
0