結果

問題 No.1315 渦巻洞穴
ユーザー tempura_pptempura_pp
提出日時 2020-12-01 03:13:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 6,068 bytes
コンパイル時間 1,339 ms
コンパイル使用メモリ 129,936 KB
実行使用メモリ 6,036 KB
最終ジャッジ日時 2023-10-11 03:18:45
合計ジャッジ時間 5,732 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 4 ms
4,432 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 3 ms
4,616 KB
testcase_17 AC 3 ms
4,364 KB
testcase_18 AC 4 ms
4,440 KB
testcase_19 AC 4 ms
4,468 KB
testcase_20 AC 5 ms
4,540 KB
testcase_21 AC 4 ms
4,792 KB
testcase_22 AC 4 ms
4,480 KB
testcase_23 AC 4 ms
4,496 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 4 ms
4,860 KB
testcase_26 AC 5 ms
5,200 KB
testcase_27 AC 4 ms
4,836 KB
testcase_28 AC 5 ms
4,952 KB
testcase_29 AC 5 ms
5,528 KB
testcase_30 AC 5 ms
5,192 KB
testcase_31 AC 4 ms
4,644 KB
testcase_32 AC 5 ms
4,580 KB
testcase_33 AC 4 ms
4,848 KB
testcase_34 AC 5 ms
4,688 KB
testcase_35 AC 5 ms
4,580 KB
testcase_36 AC 4 ms
4,820 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 3 ms
4,632 KB
testcase_39 AC 4 ms
5,280 KB
testcase_40 AC 5 ms
5,180 KB
testcase_41 AC 5 ms
5,436 KB
testcase_42 AC 6 ms
6,036 KB
testcase_43 AC 6 ms
5,444 KB
testcase_44 AC 5 ms
5,812 KB
testcase_45 AC 5 ms
5,408 KB
testcase_46 AC 6 ms
5,852 KB
testcase_47 AC 5 ms
5,364 KB
testcase_48 AC 5 ms
5,788 KB
testcase_49 AC 5 ms
5,420 KB
testcase_50 AC 5 ms
5,352 KB
testcase_51 AC 5 ms
5,776 KB
testcase_52 AC 5 ms
5,440 KB
testcase_53 AC 6 ms
5,820 KB
testcase_54 AC 5 ms
5,432 KB
testcase_55 AC 6 ms
5,852 KB
testcase_56 AC 5 ms
5,364 KB
testcase_57 AC 5 ms
5,840 KB
testcase_58 AC 6 ms
5,444 KB
testcase_59 AC 4 ms
4,644 KB
testcase_60 AC 3 ms
4,836 KB
testcase_61 AC 3 ms
4,644 KB
testcase_62 AC 4 ms
4,376 KB
testcase_63 AC 3 ms
4,376 KB
testcase_64 AC 3 ms
4,396 KB
testcase_65 AC 4 ms
4,408 KB
testcase_66 AC 4 ms
4,644 KB
testcase_67 AC 3 ms
4,392 KB
testcase_68 AC 3 ms
4,444 KB
testcase_69 AC 4 ms
4,664 KB
testcase_70 AC 3 ms
4,504 KB
testcase_71 AC 3 ms
4,436 KB
testcase_72 AC 3 ms
4,624 KB
testcase_73 AC 3 ms
4,448 KB
testcase_74 AC 3 ms
4,392 KB
testcase_75 AC 2 ms
4,352 KB
testcase_76 AC 2 ms
4,352 KB
testcase_77 AC 4 ms
4,496 KB
testcase_78 AC 3 ms
4,348 KB
testcase_79 AC 4 ms
4,356 KB
testcase_80 AC 4 ms
4,592 KB
testcase_81 AC 4 ms
4,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

vector<int> square;
pair<int,int> get(int n){
    if(n == 1)return {0, 0};
    int idx = lower_bound(square.begin(),square.end(),n)-square.begin();
    int len = (square[idx]-square[idx-1])/4;
    n -= square[idx-1];
    if(n<=len){
        return {idx, -idx+n};
    } else if(n<=2*len){
        return {idx-(n-len),idx};
    } else if(n<=3*len){
        return {-idx, idx-(n-2*len)};
    } else {
        return {-idx+(n-3*len),-idx};
    }
}

string root(vector<int> ansx, vector<int> ansy){
    string res = "";
    int n=ansx.size();
    rep(i,n-1){
        if(ansx[i]<ansx[i+1])res+='R';
        if(ansx[i]>ansx[i+1])res+='L';
        if(ansy[i]<ansy[i+1])res+='U';
        if(ansy[i]>ansy[i+1])res+='D';
    }
    return res;
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int v = 1;
    while(v*v<=2*inf){
        square.push_back(v*v);
        v+=2;
    }
    int s, t;
    cin>>s>>t;
    auto st = get(s), en = get(t);
    int sx = st.first, sy = st.second;
    int ex = en.first, ey = en.second;
    int dist = abs(ex-sx)+abs(ey-sy);
    if(dist%2 == 1){
        int cx = sx, cy = sy;
        vector<int> xs, ys;
        xs.push_back(cx); ys.push_back(cy);
        while(cx!=ex||cy!=ey){
            if(cx!=ex){
                if(cx<ex)++cx;
                else --cx;
            } else {
                if(cy<ey)++cy;
                else --cy;
            }
            xs.push_back(cx);ys.push_back(cy);
        }
        assert(xs.size()%2==0);
        vector<int> ansx, ansy;
        int n = xs.size()/2;
        rep(i,n){
            rep(j,2){
                ansx.push_back(xs[2*i]);ansy.push_back(ys[2*i]);
                ansx.push_back(xs[2*i+1]);ansy.push_back(ys[2*i+1]);
            }
        }
        string ans = root(ansx, ansy);
        cout<<0<<endl;
        cout<<ans.size()<<endl;
        cout<<ans<<endl;
    } else if((abs(sx)+abs(sy))%2 == 0){
        vector<int> ansx, ansy;
        {
            int cx = sx, cy = sy;
            vector<int> xs, ys;
            xs.push_back(cx); ys.push_back(cy);
            int tx = 0, ty = 1;
            while(cx!=tx||cy!=ty){
                if(cx!=tx){
                    if(cx<tx)++cx;
                    else --cx;
                } else {
                    if(cy<ty)++cy;
                    else --cy;
                }
                xs.push_back(cx);ys.push_back(cy);
            }
            assert(xs.size()%2==0);
            int n = xs.size()/2;
            rep(i,n){
                rep(j,2){
                    ansx.push_back(xs[2*i]);ansy.push_back(ys[2*i]);
                    ansx.push_back(xs[2*i+1]);ansy.push_back(ys[2*i+1]);
                }
            }
        }
        ansx.push_back(0);ansy.push_back(0);
        ansx.push_back(1);ansy.push_back(0);
        ansx.push_back(1);ansy.push_back(1);
        {
            int cx = 0, cy = 1;
            vector<int> xs, ys;
            xs.push_back(cx); ys.push_back(cy);
            while(cx!=ex||cy!=ey){
                if(cx!=ex){
                    if(cx<ex)++cx;
                    else --cx;
                } else {
                    if(cy<ey)++cy;
                    else --cy;
                }
                xs.push_back(cx);ys.push_back(cy);
            }
            assert(xs.size()%2==0);
            int n = xs.size()/2;
            rep(i,n){
                rep(j,2){
                    ansx.push_back(xs[2*i]);ansy.push_back(ys[2*i]);
                    ansx.push_back(xs[2*i+1]);ansy.push_back(ys[2*i+1]);
                }
            }
        }
        string ans = root(ansx, ansy);
        cout<<0<<endl;
        cout<<ans.size()<<endl;
        cout<<ans<<endl;
    } else {
        vector<int> ansx, ansy;
        {
            int cx = sx, cy = sy;
            vector<int> xs, ys;
            xs.push_back(cx); ys.push_back(cy);
            int tx = 1, ty = 1;
            while(cx!=tx||cy!=ty){
                if(cx!=tx){
                    if(cx<tx)++cx;
                    else --cx;
                } else {
                    if(cy<ty)++cy;
                    else --cy;
                }
                xs.push_back(cx);ys.push_back(cy);
            }
            assert(xs.size()%2==0);
            int n = xs.size()/2;
            rep(i,n){
                rep(j,2){
                    ansx.push_back(xs[2*i]);ansy.push_back(ys[2*i]);
                    ansx.push_back(xs[2*i+1]);ansy.push_back(ys[2*i+1]);
                }
            }
        }
        ansx.push_back(1);ansy.push_back(0);
        ansx.push_back(0);ansy.push_back(0);
        ansx.push_back(-1);ansy.push_back(0);
        ansx.push_back(0);ansy.push_back(0);
        ansx.push_back(0);ansy.push_back(1);
        {
            int cx = 1, cy = 1;
            vector<int> xs, ys;
            xs.push_back(cx); ys.push_back(cy);
            while(cx!=ex||cy!=ey){
                if(cx!=ex){
                    if(cx<ex)++cx;
                    else --cx;
                } else {
                    if(cy<ey)++cy;
                    else --cy;
                }
                xs.push_back(cx);ys.push_back(cy);
            }
            assert(xs.size()%2==0);
            int n = xs.size()/2;
            rep(i,n){
                rep(j,2){
                    ansx.push_back(xs[2*i]);ansy.push_back(ys[2*i]);
                    ansx.push_back(xs[2*i+1]);ansy.push_back(ys[2*i+1]);
                }
            }
        }
        string ans = root(ansx, ansy);
        cout<<0<<endl;
        cout<<ans.size()<<endl;
        cout<<ans<<endl;
    }
    return 0;
}
0