結果

問題 No.1315 渦巻洞穴
ユーザー tempura_pptempura_pp
提出日時 2020-12-01 03:26:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 3,003 bytes
コンパイル時間 1,265 ms
コンパイル使用メモリ 125,620 KB
実行使用メモリ 5,636 KB
最終ジャッジ日時 2023-10-11 03:19:10
合計ジャッジ時間 5,705 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,376 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,348 KB
testcase_13 AC 3 ms
4,424 KB
testcase_14 AC 3 ms
4,352 KB
testcase_15 AC 3 ms
4,372 KB
testcase_16 AC 3 ms
4,412 KB
testcase_17 AC 3 ms
4,352 KB
testcase_18 AC 4 ms
4,504 KB
testcase_19 AC 4 ms
4,596 KB
testcase_20 AC 5 ms
4,668 KB
testcase_21 AC 4 ms
4,508 KB
testcase_22 AC 4 ms
4,432 KB
testcase_23 AC 4 ms
4,532 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 4 ms
4,852 KB
testcase_26 AC 5 ms
5,104 KB
testcase_27 AC 5 ms
4,880 KB
testcase_28 AC 5 ms
4,916 KB
testcase_29 AC 5 ms
5,264 KB
testcase_30 AC 5 ms
4,756 KB
testcase_31 AC 4 ms
4,784 KB
testcase_32 AC 5 ms
4,540 KB
testcase_33 AC 5 ms
4,892 KB
testcase_34 AC 4 ms
4,672 KB
testcase_35 AC 4 ms
4,596 KB
testcase_36 AC 5 ms
4,608 KB
testcase_37 AC 2 ms
4,356 KB
testcase_38 AC 4 ms
4,348 KB
testcase_39 AC 4 ms
4,768 KB
testcase_40 AC 5 ms
5,104 KB
testcase_41 AC 5 ms
5,384 KB
testcase_42 AC 5 ms
5,564 KB
testcase_43 AC 5 ms
5,372 KB
testcase_44 AC 6 ms
5,568 KB
testcase_45 AC 5 ms
5,412 KB
testcase_46 AC 6 ms
5,636 KB
testcase_47 AC 5 ms
5,436 KB
testcase_48 AC 6 ms
5,560 KB
testcase_49 AC 5 ms
5,444 KB
testcase_50 AC 5 ms
5,340 KB
testcase_51 AC 6 ms
5,552 KB
testcase_52 AC 5 ms
5,376 KB
testcase_53 AC 5 ms
5,596 KB
testcase_54 AC 5 ms
5,444 KB
testcase_55 AC 6 ms
5,556 KB
testcase_56 AC 5 ms
5,452 KB
testcase_57 AC 5 ms
5,540 KB
testcase_58 AC 6 ms
5,432 KB
testcase_59 AC 3 ms
4,376 KB
testcase_60 AC 3 ms
4,356 KB
testcase_61 AC 3 ms
4,592 KB
testcase_62 AC 3 ms
4,388 KB
testcase_63 AC 3 ms
4,388 KB
testcase_64 AC 3 ms
4,348 KB
testcase_65 AC 3 ms
4,396 KB
testcase_66 AC 3 ms
4,404 KB
testcase_67 AC 3 ms
4,420 KB
testcase_68 AC 4 ms
4,408 KB
testcase_69 AC 4 ms
4,484 KB
testcase_70 AC 4 ms
4,408 KB
testcase_71 AC 3 ms
4,408 KB
testcase_72 AC 4 ms
4,376 KB
testcase_73 AC 4 ms
4,436 KB
testcase_74 AC 3 ms
4,492 KB
testcase_75 AC 2 ms
4,352 KB
testcase_76 AC 1 ms
4,352 KB
testcase_77 AC 4 ms
4,492 KB
testcase_78 AC 3 ms
4,348 KB
testcase_79 AC 4 ms
4,348 KB
testcase_80 AC 4 ms
4,612 KB
testcase_81 AC 4 ms
4,600 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, ansx, ansy;
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;
}

void makeEvenRoot(int sx, int sy, int ex, int ey) {
    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);
        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]);
            }
        }
}
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){
        makeEvenRoot(sx, sy, ex, ey);
    } else if((abs(sx)+abs(sy))%2 == 0){
        makeEvenRoot(sx, sy, 0, 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);
        makeEvenRoot(0, 1, ex, ey);
    } else {
        makeEvenRoot(sx, sy, 0, 0);
        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);
        makeEvenRoot(0, 0, ex, ey);
    }
    string ans = root(ansx, ansy);
        cout<<0<<endl;
        cout<<ans.size()<<endl;
        cout<<ans<<endl;
    return 0;
}
0