結果
問題 | No.1315 渦巻洞穴 |
ユーザー |
👑 ![]() |
提出日時 | 2020-12-12 00:27:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,361 bytes |
コンパイル時間 | 2,233 ms |
コンパイル使用メモリ | 195,616 KB |
最終ジャッジ日時 | 2025-01-16 22:29:18 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 79 |
ソースコード
#include<bits/stdc++.h>using namespace std;using LL=long long;using ULL=unsigned long long;#define rep(i,n) for(int i=0;i<(n);i++)struct Pos{ int x,y; };Pos id_to_pos(int id){if(id==1) return {0,0};id--;for(int i=1;; i++){int shed=2*i;int off=(shed-1)*(shed-1);int minp=-i+1;if(id-off<shed) return { i,(minp+(id-off)) };if(id-off-shed<shed) return { -(minp+(id-off-shed)),i };if(id-off-shed*2<shed) return { -i,-(minp+(id-off-shed*2)) };if(id-off-shed*3<shed) return { (minp+(id-off-shed*3)),-i };}}const string dirs="ULDR";string reverse_moving(const string& src){string res = src;reverse(res.begin(),res.end());for(char& c:res) c=dirs[dirs.find(c)^2];return move(res);}string move_to_origin(Pos x){string res;res+="RLR"; x.x++;while(x.x>1){ res+="LLRL"; x.x-=2; }while(x.x<0){ res+="RRLR"; x.x+=2; }while(x.y>1){ res+="DDUD"; x.y-=2; }while(x.y<0){ res+="UUDU"; x.y+=2; }if(x.x==1 && x.y==1){ res+="DLRL"; x={0,0}; }if(x.x==0 && x.y==1){ res+="DRLR"; x={1,0}; }if(x.x==1){ res+="UDL"; x={0,0}; }return move(res);}int main(){Pos S,T;{ int s,t; cin>>s>>t; S=id_to_pos(s); T=id_to_pos(t); }string ans = move_to_origin(S) + "URDLUD" + reverse_moving(move_to_origin(T));cout<<0<<endl;cout<<ans.size()<<endl;cout<<ans<<endl;return 0;}