結果

問題 No.1315 渦巻洞穴
ユーザー milanis48663220milanis48663220
提出日時 2020-12-12 22:05:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,605 bytes
コンパイル時間 1,181 ms
コンパイル使用メモリ 113,588 KB
実行使用メモリ 5,176 KB
最終ジャッジ日時 2023-10-20 02:41:15
合計ジャッジ時間 4,690 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <cmath>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

struct poll{
    ll x, y;
};

const double eps = 0.01;

ll right_up(ll k){ return (2*k-1)*(2*k-1)+(2*k); }
ll left_up(ll k){ return (2*k)*(2*k)+1; }
ll left_bottom(ll k){ return (2*k)*(2*k)+2*k+1; }
ll right_bottom(ll k){ return (2*k+1)*(2*k+1); }

ll sqrt_ll(ll n){
    return (ll)(sqrt(n)+eps);
}

ll to_cycle(ll n){
    ll s = sqrt_ll(n);
    if(s%2 == 0) s--;
    if(s*s == n){
        return (s+1)/2-1;
    }
    return (s+3)/2-1;
}

poll to_cood(ll n){
    ll k = to_cycle(n);
    ll x = -1, y = -1;
    if(n <= right_up(k)){
        x = k, y = k-(right_up(k)-n);
    }else if(n <= left_up(k)){
        x = -k+(left_up(k)-n), y = k;
    }else if(n <= left_bottom(k)){
        x = -k, y = -k+(left_bottom(k)-n);
    }else{
        x = k-(right_bottom(k)-n), y = -k;
    }
    return (poll){x, y};
}

ll to_number(poll p){
    ll k = max(abs(p.x), abs(p.y));
    if(p.x == k){
        return right_up(k)-(k-p.y);
    }else if(p.y == k){
        return left_up(k)-(p.x+k);
    }else if(p.x == -k){
        return left_bottom(k)-(p.y+k);
    }else{
        return right_bottom(k)-(k-p.x);        
    }
}

ll dist(poll p1, poll p2){
    return abs(p1.x-p2.x)+abs(p1.y-p2.y);
}

ll s, t;
ll x, y;
ll sx, sy, tx, ty;

vector<ll> vx, vy;

void go_up(){
    y++;
    vx.push_back(x);
    vy.push_back(y);
}

void go_down(){
    y--;
    vx.push_back(x);
    vy.push_back(y);
}

void go_left(){
    x--;
    vx.push_back(x);
    vy.push_back(y);
}

void go_right(){
    x++;
    vx.push_back(x);
    vy.push_back(y);
}

void solve_odd(){
    while(x != tx){
        if(x < tx) go_right();
        else go_left();
    }
    while(y != ty){
        if(y < ty) go_up();
        else go_down();
    }
    ll sz = vx.size();
    string ans;
    for(ll i = 0; i < sz-1; i++){
        if(i%2 == 0){
            if(vx[i+1] == vx[i]+1) ans += "RLR";
            if(vx[i+1] == vx[i]-1) ans += "LRL";
            if(vy[i+1] == vy[i]+1) ans += "UDU";
            if(vy[i+1] == vy[i]-1) ans += "DUD";
        }else{
            if(vx[i+1] == vx[i]+1) ans += "R";
            if(vx[i+1] == vx[i]-1) ans += "L";
            if(vy[i+1] == vy[i]+1) ans += "U";
            if(vy[i+1] == vy[i]-1) ans += "D";
        }
    }
    assert(ans.size() <= 200000); 
    cout << 0 << endl;
    cout << ans.size() << endl;
    cout << ans << endl;
}


void solve_even(){
    ll u = s^t;
    auto pu = to_cood(u);
    ll ux = pu.x, uy = pu.y;
    while(x != ux){
        if(x < ux) go_right();
        else go_left();
    }
    while(y != uy){
        if(y < uy) go_up();
        else go_down();
    }
    while(x != tx){
        if(x < tx) go_right();
        else go_left();
    }
    while(y != ty){
        if(y < ty) go_up();
        else go_down();
    }
    ll sz = vx.size();
    ll i = 0;
    string ans;
    for(ll j = 0; j < sz-1; j++){
        if(i%2 == 1){
            if(vx[j+1] == vx[j]+1) ans += "RLR";
            if(vx[j+1] == vx[j]-1) ans += "LRL";
            if(vy[j+1] == vy[j]+1) ans += "UDU";
            if(vy[j+1] == vy[j]-1) ans += "DUD";
        }else{
            if(vx[j+1] == vx[j]+1) ans += "R";
            if(vx[j+1] == vx[j]-1) ans += "L";
            if(vy[j+1] == vy[j]+1) ans += "U";
            if(vy[j+1] == vy[j]-1) ans += "D";
        }
        if(vx[j+1] != ux || vy[j+1] != uy) i++;
    }
    assert(ans.size() <= 200000); 
    cout << 0 << endl;
    cout << ans.size() << endl;
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> s >> t;
    auto ps = to_cood(s);
    auto pt = to_cood(t);
    x = ps.x, y = ps.y;
    sx = ps.x, sy = ps.y;
    tx = pt.x, ty = pt.y;
    vx.push_back(sx);
    vy.push_back(sy);
    if(dist(ps, pt)%2 == 0){
        solve_even();
    }else{
        solve_odd();
    }
    // cout << ps.x << ' ' << ps.y << endl;
    // cout << pt.x << ' ' << pt.y << endl;
    for(ll i = 1; i <= 100; i++) {
        auto p = to_cood(i);
        cout << p.x << ',' << p.y << ' ';
    }
    cout << endl;
}
0