結果
問題 | No.1315 渦巻洞穴 |
ユーザー | pes_magic |
提出日時 | 2020-12-12 13:02:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 2,479 bytes |
コンパイル時間 | 670 ms |
コンパイル使用メモリ | 70,432 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-19 21:55:05 |
合計ジャッジ時間 | 3,766 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 79 |
コンパイルメッセージ
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); | ^
ソースコード
#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; }