結果

問題 No.1315 渦巻洞穴
ユーザー Haa
提出日時 2020-12-12 21:08:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,921 bytes
コンパイル時間 1,509 ms
コンパイル使用メモリ 170,652 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-19 22:17:08
合計ジャッジ時間 10,269 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 29 WA * 50
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'std::pair<int, int> point(int)':
main.cpp:44:1: warning: control reaches end of non-void function [-Wreturn-type]
   44 | }
      | ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=998244353;
constexpr ll INF=1e18;

pair<int,int> point(int n){
    if(n==1)
        return {0,0};
    ll k;
    for(k=1;1;k+=2){
        if(k*k>n){
            k-=2;
            break;
        }
    }
    int now=k*k;
    int x=(k+1)/2, y=(k+1)/2;
    REP(i,k+1){
        y--; now++;
        if(now==n)
            return {x,y};
    }
    REP(i,k+1){
        x--; now++;
        if(now==n)
            return {x,y};
    }
    REP(i,k+1){
        y++; now++;
        if(now==n)
            return {x,y};
    }
    REP(i,k+1){
        x++; now++;
        if(now==n)
            return {x,y};
    }
}

string path(int dx, int dy){
    string ret="";
    if(dx>0){
        REP(i,dx/2)
            ret+="RRLR";
    }
    else{
        REP(i,-dx/2)
            ret+="LLRL";
    }
    if(dy>0){
        REP(i,dy/2)
            ret+="DDUD";
    }
    else{
        REP(i,-dy/2)
            ret+="UUDU";
    }
    return ret;
}

int main(){
    int s, t; cin >> s >> t;
    pair<int,int> sp=point(s), tp=point(t);
    string ans="RLR";
    sp.first++;
    int dx=tp.first-sp.first, dy=tp.second-sp.second;
    if(abs(dx)%2==0&&abs(dy)%2==0){
        ans+=path(dx,dy);
    }
    else{
        if(abs(sp.second)%2!=abs(tp.second)%2){
            ans+="RDUD";
            sp.first++;
            sp.second++; 
        }
        if(abs(sp.first)%2!=abs(tp.first)%2){
            if(abs(sp.second)%2==0){
                if(abs(sp.first)%2==0){
                    dx=-2-sp.first;
                    dy=-sp.second;
                    ans+=path(dx,dy);
                    ans+="UUR";
                    sp.first+=dx+1;
                    sp.second+=dy-2;
                }
                else{
                    dx=-1-sp.first;
                    dy=-2-sp.second;
                    ans+=path(dx,dy);
                    ans+="LDD";
                    sp.first+=dx-1;
                    sp.second+=dy+2;
                }
            }
            else{
                if(abs(sp.first)%2==0){
                    dx=-sp.first;
                    dy=-1-sp.second;
                    ans+=path(dx,dy);
                    ans+="LDD";
                    sp.first+=dx-1;
                    sp.second+=dy+2;
                }
                else{
                    dx=-1-sp.first;
                    dy=1-sp.second;
                    ans+=path(dx,dy);
                    ans+="UUR";
                    sp.first+=dx+1;
                    sp.second+=dy-2;
                }
            }
        }
        dx=tp.first-sp.first;
        dy=tp.second-sp.second;
        ans+=path(dx,dy);
    }
    cout << 0 << endl;
    cout << ans.size() << endl;
    cout << ans << endl;
    return 0;
}
0