結果

問題 No.1315 渦巻洞穴
ユーザー pes_magicpes_magic
提出日時 2020-12-12 13:02:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,479 bytes
コンパイル時間 628 ms
コンパイル使用メモリ 69,900 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-20 02:06:17
合計ジャッジ時間 4,028 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 2 ms
4,368 KB
testcase_11 AC 2 ms
4,368 KB
testcase_12 AC 2 ms
4,368 KB
testcase_13 AC 2 ms
4,368 KB
testcase_14 AC 3 ms
4,368 KB
testcase_15 AC 2 ms
4,368 KB
testcase_16 AC 3 ms
4,368 KB
testcase_17 AC 2 ms
4,368 KB
testcase_18 AC 2 ms
4,368 KB
testcase_19 AC 3 ms
4,368 KB
testcase_20 AC 3 ms
4,368 KB
testcase_21 AC 2 ms
4,368 KB
testcase_22 AC 2 ms
4,368 KB
testcase_23 AC 3 ms
4,368 KB
testcase_24 AC 2 ms
4,368 KB
testcase_25 AC 2 ms
4,368 KB
testcase_26 AC 2 ms
4,368 KB
testcase_27 AC 3 ms
4,368 KB
testcase_28 AC 2 ms
4,368 KB
testcase_29 AC 3 ms
4,368 KB
testcase_30 AC 3 ms
4,368 KB
testcase_31 AC 3 ms
4,368 KB
testcase_32 AC 2 ms
4,368 KB
testcase_33 AC 3 ms
4,368 KB
testcase_34 AC 2 ms
4,368 KB
testcase_35 AC 2 ms
4,368 KB
testcase_36 AC 2 ms
4,368 KB
testcase_37 AC 2 ms
4,368 KB
testcase_38 AC 3 ms
4,368 KB
testcase_39 AC 3 ms
4,368 KB
testcase_40 AC 3 ms
4,368 KB
testcase_41 AC 3 ms
4,368 KB
testcase_42 AC 2 ms
4,368 KB
testcase_43 AC 3 ms
4,368 KB
testcase_44 AC 3 ms
4,368 KB
testcase_45 AC 3 ms
4,368 KB
testcase_46 AC 4 ms
4,368 KB
testcase_47 AC 3 ms
4,368 KB
testcase_48 AC 3 ms
4,368 KB
testcase_49 AC 3 ms
4,368 KB
testcase_50 AC 3 ms
4,368 KB
testcase_51 AC 3 ms
4,368 KB
testcase_52 AC 3 ms
4,368 KB
testcase_53 AC 2 ms
4,368 KB
testcase_54 AC 3 ms
4,368 KB
testcase_55 AC 2 ms
4,368 KB
testcase_56 AC 3 ms
4,368 KB
testcase_57 AC 4 ms
4,368 KB
testcase_58 AC 3 ms
4,368 KB
testcase_59 AC 3 ms
4,368 KB
testcase_60 AC 3 ms
4,368 KB
testcase_61 AC 3 ms
4,368 KB
testcase_62 AC 3 ms
4,368 KB
testcase_63 AC 3 ms
4,368 KB
testcase_64 AC 2 ms
4,368 KB
testcase_65 AC 2 ms
4,368 KB
testcase_66 AC 2 ms
4,368 KB
testcase_67 AC 2 ms
4,368 KB
testcase_68 AC 2 ms
4,368 KB
testcase_69 AC 2 ms
4,368 KB
testcase_70 AC 3 ms
4,368 KB
testcase_71 AC 2 ms
4,368 KB
testcase_72 AC 3 ms
4,368 KB
testcase_73 AC 2 ms
4,368 KB
testcase_74 AC 3 ms
4,368 KB
testcase_75 AC 1 ms
4,368 KB
testcase_76 AC 2 ms
4,368 KB
testcase_77 AC 2 ms
4,368 KB
testcase_78 AC 2 ms
4,368 KB
testcase_79 AC 2 ms
4,368 KB
testcase_80 AC 2 ms
4,368 KB
testcase_81 AC 2 ms
4,368 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:70:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   70 |     auto [sx, sy] = pos(S);
      |          ^
main.cpp:71:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   71 |     auto [gx, gy] = pos(T);
      |          ^
main.cpp:72:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   72 |     auto [res, val] = getPath(sx, sy, gx, gy);
      |          ^
main.cpp:78:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   78 |     auto [px, py] = pos(val);
      |          ^

ソースコード

diff #

#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int getValue(int x, int y){
    int v = max(abs(x), abs(y));
    if(v == 0) return 1;
    int base = (2*v+1) * (2*v+1);
    if(y == -v) return base - (v-x);
    base -= 2*v;
    if(x == -v) return base - (v+y);
    base -= 2*v;
    if(y == v) return base - (v+x);
    base -= 2*v;
    return base - (v-y);
}

pair<int, int> pos(int v){
    if(v == 1) return make_pair(0, 0);
    int b = 0;
    while((2*b+1)*(2*b+1) < v) b++;
    v -= (2*b-1)*(2*b-1) + 1;
    int x = b, y = -b+1;
    if(v < 2*b) return make_pair(b, -b+1+v);
    v -= 2*b;
    if(v < 2*b) return make_pair(b-1-v, b);
    v -= 2*b;
    if(v < 2*b) return make_pair(-b, b-1-v);
    v -= 2*b;
    return make_pair(-b+1+v, -b);
}

pair<string, int> getPath(int sx, int sy, int gx, int gy){
    string res = "";
    int val = 0;
    int x = sx, y = sy;
    while(x != gx){
        val ^= getValue(x, y);
        if(x < gx){
            res += 'R';
            x++;
        } else {
            res += 'L';
            x--;
        }
    }
    while(y != gy){
        val ^= getValue(x, y);
        if(y < gy){
            res += 'U';
            y++;
        } else {
            res += 'D';
            y--;
        }
    }
    return make_pair(res, val);
}

int main(){
    int S, T; cin >> S >> T;
    // while(true){
    // int S = 0, T = 0;
    // while(S==T){
    //     S = rand()%1000000000+1;
    //     T = rand()%1000000000+1;
    // }
    auto [sx, sy] = pos(S);
    auto [gx, gy] = pos(T);
    auto [res, val] = getPath(sx, sy, gx, gy);
    if(val == 0){
        res += "LRUD";
        val ^= getValue(gx-1, gy);
        val ^= getValue(gx, gy+1);
    }
    auto [px, py] = pos(val);
    auto m = getPath(gx, gy, px, py).first;
    res += m;
    for(int i=m.size()-1;i>=0;i--){
        if(m[i] == 'L') res += 'R';
        if(m[i] == 'R') res += 'L';
        if(m[i] == 'U') res += 'D';
        if(m[i] == 'D') res += 'U';
    }
    // int v = S;
    // int x = sx, y = sy;
    // for(auto& c : res){
    //     if(c == 'L') --x;
    //     if(c == 'R') ++x;
    //     if(c == 'D') --y;
    //     if(c == 'U') ++y;
    //     v ^= getValue(x, y);
    // }
    // if(x != gx || y != gy || v != 0){
    //     cout << S << " " << T << endl;
    //     break;
    // }
    cout << 0 << endl;
    cout << res.size() << endl;
    cout << res << endl;
    // cout << x << " " << y << " " << gx << " " << gy << " " << v << endl;
}
0