結果

問題 No.3278 Avoid Division
ユーザー eQe
提出日時 2025-09-19 22:33:07
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,621 bytes
コンパイル時間 5,341 ms
コンパイル使用メモリ 330,592 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-09-19 22:34:21
合計ジャッジ時間 7,389 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 2 WA * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#if __has_include(<atcoder/all>)
#endif
using namespace std;
#define eb emplace_back
#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 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};}
void lin(auto&...a){(cin>>...>>a);}
void vin(auto&...a){fo(i,(a.size()&...))(cin>>...>>a[i]);}
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;}
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 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>{
  using vector<V>::vector;
  ll size()const{return vector<V>::size();}
  auto&emplace_back(auto&&...a){vector<V>::emplace_back(std::forward<decltype(a)>(a)...);return*this;}
  auto flatten()const{if constexpr(!vectorial<V>)return*this;else{ }}
  auto unique()const{auto res=flatten();return my::unique(res);}
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
}
#include<format>
namespace my{entry
void main(){
  LL(N);
  vec<char>c(N);
  vec<ll>a(N);
  vin(c,a);

  if(c.unique().size()==1){
    if(c[0]=='+'){
      pp(N);
      fo(i,N)pp(format("add a a A[{}]",i+1));
      return;
    }
  }
  // p/qで持つ
  vec<string>res;
  res.eb(format("add q q 1"));
  fo(i,N){
    if(c[i]=='+'){ // p/q+x=(p+q*x)/q
      res.eb(format("mul t q A[{}]",i+1));
      res.eb(format("add p p t"));
    }
    else if(c[i]=='*'){
      res.eb(format("mul p p A[{}]",i+1));
    }
    else if(c[i]=='/'){
      res.eb(format("mul q q A[{}]",i+1));
    }
  }
  res.eb(format("div a p q"));

  pp(res.size());
  fe(res,e)pp(e);
}}
0