結果

問題 No.2307 [Cherry 5 th Tune *] Cool 46
ユーザー eQe
提出日時 2025-03-24 03:19:26
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 5,704 bytes
コンパイル時間 7,107 ms
コンパイル使用メモリ 332,896 KB
実行使用メモリ 17,312 KB
最終ジャッジ日時 2025-03-24 03:19:50
合計ジャッジ時間 22,343 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
namespace my{
#define eb emplace_back
#define done(...) return pp(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__)
#define RDVL(T,n,...) vec<T>__VA_ARGS__;resizes({n},__VA_ARGS__);lin(__VA_ARGS__)
#define VL(n,...) RDVL(ll,n,__VA_ARGS__)
#define FO(n) for(ll ij=n;ij-->0;)
#define FOR(i,...) for(auto[i,i##stop,i##step]=range(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define fo(i,...) FO##__VA_OPT__(R)(i __VA_OPT__(,__VA_ARGS__))
#define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a)
#define schrodinger(p,c) (p?c:remove_cvref_t<decltype(c)>{})
#define base_operator(op,type) auto operator op(const type&v)const{auto copy=*this;return copy op##=v;}
#define single_testcase void solve();}int main(){my::io();my::solve();}namespace my{
void io(){cerr<<endl;cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
using ll=long long;
constexpr auto range(ll s,ll b){ll a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};}
constexpr auto range(ll s,ll a,ll b,ll c=1){return array{a-s,b,(1-s*2)*c};}
const string newline{char(10)};
const string space{char(32)};

template<class A,class B>struct pair{
  A a;B b;
  pair()=default;
  pair(A a,B b):a(a),b(b){}
  pair(const std::pair<A,B>&p):a(p.first),b(p.second){}
  auto operator<=>(const pair&)const=default;
  pair operator+(const pair&p)const{return{a+p.a,b+p.b};}
  friend istream&operator>>(istream&i,pair&p){return i>>p.a>>p.b;}
  friend ostream&operator<<(ostream&o,const pair&p){return o<<p.a<<space<<p.b;}
};

template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;

template<class V>concept vectorial=is_base_of_v<vector<typename remove_cvref_t<V>::value_type>,remove_cvref_t<V>>;
template<class V>constexpr int rank(){if constexpr(vectorial<V>)return rank<typename V::value_type>()+1;else return 0;}
template<class T>struct core_t_helper{using core_t=T;};
template<vectorial V>struct core_t_helper<V>{using core_t=typename core_t_helper<typename V::value_type>::core_t;};
template<class T>using core_t=core_t_helper<T>::core_t;
template<class V>istream&operator>>(istream&i,vector<V>&v){fe(v,e)i>>e;return i;}
template<class V>ostream&operator<<(ostream&o,const vector<V>&v){ll n=v.size();fo(i,n)o<<v[i]<<schrodinger(i<n-1,vectorial<V>?newline:space);return o;}

template<class V>struct vec;
template<int rank,class T>struct hvec_helper{using type=vec<typename hvec_helper<rank-1,T>::type>;};
template<class T>struct hvec_helper<0,T>{using type=T;};
template<int rank,class T>using hvec=typename hvec_helper<rank,T>::type;

template<class V>struct vec:vector<V>{
  static constexpr int R=rank<vec<V>>();
  using C=core_t<V>;
  using vector<V>::vector;
  vec(const vector<V>&v){vector<V>::operator=(v);}
  vec(const auto&...a)requires(sizeof...(a)>=3){resizes(a...);}
  void resizes(const auto&...a){*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...));}

  vec&operator^=(const vec&u){this->insert(this->end(),u.begin(),u.end());return*this;}
  vec&operator+=(const vec&u){vec&v=*this;assert(v.size()==u.size());fo(i,v.size())v[i]+=u[i];return v;}
  vec&operator-=(const vec&u){vec&v=*this;assert(v.size()==u.size());fo(i,v.size())v[i]-=u[i];return v;}
  base_operator(^,vec)
  base_operator(+,vec)
  base_operator(-,vec)

  vec&operator++(){fe(*this,e)++e;return*this;}
  vec&operator--(){fe(*this,e)--e;return*this;}

  ll size()const{return vector<V>::size();}

  auto lower_bound(const V&x)const{return std::lower_bound(this->begin(),this->end(),x);}
  ll arg_lower_bound(const V&x)const{return lower_bound(x)-this->begin();}

  template<class F=less<>>auto sort(F f={})const{vec v=*this;ranges::sort(v,f);return v;}

  auto flatten()const{if constexpr(!vectorial<V>)return*this;else{vec<C>res;fe(*this,e)res^=e.flatten();return res;}}
  auto unique()const{auto res=flatten().sort();sort(res).erase(ranges::unique(res).begin(),res.end());return res;}

  auto zip_impl(const vec<C>&v)const{
    hvec<R,ll>res;res.reserve(size());
    fe(*this,e)if constexpr(vectorial<V>)res.eb(e.zip_impl(v));else res.eb(v.arg_lower_bound(e));
    return res;
  }
  auto zip()const{return zip_impl(unique());}
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
vec(ll)->vec<ll>;

template<class...A>void resizes(const array<ll,common_type_t<A...>::R+1>&s,A&...a){(apply([&](const auto&...b){a.resizes(b...); },s),...);}

void lin(auto&...a){(cin>>...>>a);}
void pp(const auto&...a){ll n=sizeof...(a);((cout<<a<<schrodinger(--n>0,space)),...);cout<<newline;}
auto Yes(bool p=1){return p?"Yes":"No";}
auto No(){return Yes(0);}

template<class F=less<>>auto&sort(auto&a,F f={}){ranges::sort(a,f);return a;}
auto&unique(auto&a){sort(a).erase(ranges::unique(a).begin(),a.end());return a;}

auto zip(auto&...a){auto v=(a^...);unique(v);([&](auto&u){fe(u,e)e=v.arg_lower_bound(e);}(a),...);return v;}

single_testcase
void solve(){
  LL(N,M);
  VL(N,a);
  VL(M,b);

  auto v=zip(a,b);
  ll C=v.size();
  vec cnt(C,2,-1);
  fo(i,N)cnt[a[i]][0]=i;
  fo(i,M)cnt[b[i]][1]=i;

  vec<pair<ll,ll>>res;
  fo(i,C)if(cnt[i][0]!=-1&&cnt[i][1]==-1)res.eb(0,i);

  ll k=-1;
  fo(i,C){
    if(cnt[i][0]!=-1&&cnt[i][1]!=-1){
      res.eb(0,i);
      res.eb(1,i);
      k=i;
      break;
    }
  }
  if(N&&M&&k==-1)done(No());

  fo(i,C)if(cnt[i][0]==-1&&cnt[i][1]!=-1)res.eb(1,i);

  ll r=1;
  fo(i,C)if(k!=i){
    if(cnt[i][0]!=-1&&cnt[i][1]!=-1){
      res.eb(r,i);
      res.eb(1-r,i);
      r=1-r;
    }
  }

  pp(Yes());
  fe(res,e)pp((e.a==0?"Red":"Blue"),v[e.b]);
}}
0