結果
問題 | No.5006 Hidden Maze |
ユーザー |
![]() |
提出日時 | 2022-06-12 17:54:42 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 6,440 bytes |
コンパイル時間 | 2,311 ms |
実行使用メモリ | 22,868 KB |
スコア | 0 |
平均クエリ数 | 1001.00 |
最終ジャッジ日時 | 2022-06-12 17:54:54 |
合計ジャッジ時間 | 11,547 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 100 |
ソースコード
#pragma GCC optimize("Ofast")#pragma GCC optimize("unroll-loops")#pragma GCC optimize("inline")#pragma GCC diagnostic ignored "-Wunused-value"#include<bits/stdc++.h>using namespace std;/** Additional Type Definition*/using ll=long long;using ld=long double;using ull=unsigned long long;using vb=vector<bool>;using vvb=vector<vb>;using vd=vector<ld>;using vvd=vector<vd>;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using pii=pair<int,int>;using pll=pair<ll,ll>;using vp=vector<pll>;using tl2=tuple<ll,ll>;using tl3=tuple<ll,ll,ll>;using vs=vector<string>;#define all(a) begin(a),end(a)#define rall(a) rbegin(a),rend(a)#define __LOOPSWITCH(_1, _2, _3, __LOOPSWITCH, ...) __LOOPSWITCH#define rep(...) __LOOPSWITCH(__VA_ARGS__, __RANGE, __REP, __LOOP) (__VA_ARGS__)#define rrep(...) __LOOPSWITCH(__VA_ARGS__, __RRANGE, __RREP, __LOOP) (__VA_ARGS__)#define __LOOP(q) __LOOP2(q, __LINE__)#define __LOOP2(q,l) __LOOP3(q,l)#define __LOOP3(q,l) __REP(_lp ## l,q)#define __REP(i,n) __RANGE(i,0,n)#define __RANGE(i,a,n) for(ll i=((ll)a);i<((ll)n);++i)#define __RREP(i,n) __RRANGE(i,0,n)#define __RRANGE(i,a,n) for(ll i=((ll)(n)-1);i>=((ll)a);--i)#define sz(a) ((ll)(a).size())/** Constants*/constexpr ll LINF=1ll<<60;constexpr int INF=1<<30;constexpr double EPS=(1e-14);constexpr ll MOD=998244353ll;constexpr long double PI=3.14159265358979323846;/** Utilities*/template<class T>constexpr bool chmax(T&a,T b){return a<b?a=b,1:0;}template<class T>constexpr bool chmin(T&a,T b){return a>b?a=b,1:0;}template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}template<class S>S max(vector<S>&a){return *max_element(all(a));}template<class S>S min(vector<S>&a){return *min_element(all(a));}namespace IO {// container detectiontemplate<typename T, typename _=void> struct is_container : false_type {};template<> struct is_container<string> : false_type {};template<typename...Ts> struct is_container_helper {};template<typename T> struct is_container<T, conditional_t<true, void, is_container_helper<typename T::value_type, typename T::size_type, typename T::iterator,decltype(declval<T>().size()),decltype(declval<T>().begin()),decltype(declval<T>().end()) >>> : public true_type {};template<typename T,typename enable_if<is_container<T>{}, nullptr_t>::type = nullptr,char Separator = is_container<typename T::value_type>{} ? '\n' : ' ' >constexpr ostream&operator<<(ostream&os, T t){if(auto b=begin(t), e=end(t) ; !t.empty()) for(os<<(*b++);b!=e;os<<Separator<<(*b++)) ;return os;}// outputtemplate<class T, class...Ts> constexpr ostream& pargs(ostream&os, T&&t, Ts&&...args); // support clangtemplate<class S,class T>constexpr ostream&operator<<(ostream&os,pair<S,T>p){ return os<<'['<<p.first<<", "<<p.second<<']'; };template<class...Ts>constexpr ostream&operator<<(ostream&os,tuple<Ts...>t){return apply([&os](auto&&t,auto&&...args)->ostream&{return pargs(os, t, args...);}, t);};template<class T, class...Ts> constexpr ostream& pargs(ostream&os, T&&t, Ts&&...args) {return ((os<<t)<<...<<(os<<' ', args));}template<class...Ts> constexpr ostream& out(Ts...args) { return pargs(cout, args...)<<'\n'; }template<class...Ts> constexpr ostream& debug_f(Ts...args) { return pargs(cerr, args...)<<'\n'; }#ifdef _DEBUGtemplate<class...Ts> constexpr ostream& debug(Ts...args) { return pargs(cerr, args...)<<'\n'; }#else#define debug(...) if(false)debug_f(__VA_ARGS__)#endifvoid Yn(bool f) { out(f?"Yes":"No"); }// inputtemplate<class T, class...Ts> constexpr istream& gargs(istream&is, T&&t, Ts&&...args) {return ((is>>t)>>...>>args);}template<class S,class T>auto&operator>>(istream&is,pair<S,T>&p){return is>>p.first>>p.second;}template<class...Ts>constexpr istream&operator>>(istream&is,tuple<Ts...>&t){return apply([&is](auto&&t,auto&&...args)->istream&{return gargs(is, t, args...);}, t);};template<typename...S>auto&in(S&...s){return gargs(cin, s...);}#define def(t,...) t __VA_ARGS__; in(__VA_ARGS__)template<typename T, typename enable_if<is_container<T>{}, nullptr_t>::type = nullptr>auto&operator>>(istream&is,T&t){for(auto&a:t)is>>a; return is;}}using namespace IO;class Random {public:typedef uint_fast32_t result_type;constexpr result_type operator()(){return operator()((ll)min(),(ll)max());}static constexpr result_type max(){return numeric_limits<result_type>::max();}static constexpr result_type min(){return 0;}constexpr Random(const bool&isDeterministic):y(isDeterministic?2463534242:chrono::system_clock::now().time_since_epoch().count()){}constexpr int operator()(int a,int b){return next()%(b-a)+a;}constexpr ll operator()(ll a,ll b){return (((ull)next())<<32|next())%(b-a)+a;}constexpr double operator()(double a,double b){return (b-a)*next()/4294967296.0+a;}private:result_type y;constexpr result_type next(){return y^=(y^=(y^=y<<13)>>17)<<5;}} Random(0);class Timer {#ifdef _DEBUGstatic constexpr uint64_t ClocksPerMsec = 3587000;#elsestatic constexpr uint64_t ClocksPerMsec = 2987000;#endifconst uint64_t start,limit;uint64_t getClocks() const{unsigned int lo,hi;__asm__ volatile ("rdtsc" : "=a" (lo), "=d" (hi));return((uint64_t)hi<<32)|lo;}public:Timer(uint64_t _limit=1970): start(getClocks()),limit(start+_limit*ClocksPerMsec) {}uint64_t get() const{return (getClocks()-start)/ClocksPerMsec;}operator bool()const{return getClocks()<limit;}};void wait(const int&msec){Timer tm(msec); while(tm);}struct Mgr {static const int TLE = 2000;static inline Timer timer = Timer(TLE-20);Mgr() {ios_base::sync_with_stdio(0); cin.tie(0);cout<<fixed<<setprecision(11);cerr<<fixed<<setprecision(3);}~Mgr(){debug_f(timer.get(), "ms")<<flush;}} _manager;int main() {map<char,int> enc;enc['L']=0;enc['U']=1;enc['R']=2;enc['D']=3;string dec="LURD";/**/def(int,h,w,p);deque<tuple<string,int,int>> q;q.emplace_back("D",0,0);q.emplace_back("R",0,0);while(!q.empty()){auto [s,fail,ret]=q.front();q.pop_front();out(s)<<flush;def(int,t);if(t==-1)break;if(sz(s)==t){rep(i,4)if(s.back()!=dec[i^2]){q.emplace_front(s+dec[i], 0, t);}}else{if(fail<3){q.emplace_front(s,fail+1, max(ret, t));}else{q.emplace_back(s.substr(0,max(ret, t)), 0, max(ret, t));}}}}