jainbot27

bug

Jul 22nd, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.34 KB | None | 0 0
  1. #pragma GCC optimize ("O3")
  2. #pragma GCC target("sse4")
  3. #include <bits/stdc++.h>
  4. #define f first
  5. #define s second
  6. #define pb push_back
  7. #define mp make_pair
  8. #define ts to_string
  9. #define ub upper_bound
  10. #define lb lower_bound
  11. const char nl = '\n';
  12. using namespace std;
  13. using ll = long long;
  14. using vi = vector<int>;
  15. using vl = vector<ll>;
  16. using pii = pair<int, int>;
  17. using pll = pair<ll, ll>;
  18. using str = string;
  19. //The following debugging code was taken from Benjamin Qi's template :)
  20. str ts(char c) { return str(1,c); }
  21. str ts(bool b) { return b ? "true" : "false"; }
  22. str ts(const char* s) { return (str)s; }
  23. str ts(str s) { return s; }
  24. template<class A> str ts(complex<A> c) {
  25.     stringstream ss; ss << c; return ss.str(); }
  26. str ts(vector<bool> v) {
  27.     str res = "{"; for(int i = 0;i < (int)v.size(); i++) res += char('0'+v[i]);
  28.     res += "}"; return res; }
  29. template<size_t SZ> str ts(bitset<SZ> b) {
  30.     str res = ""; for(int i = 0; i < b.size(); i++) res += char('0'+b[i]);
  31.     return res; }
  32. template<class A, class B> str ts(pair<A,B> p);
  33. template<class T> str ts(T v) {
  34.     bool fst = 1; str res = "{";
  35.     for (const auto& x: v) {
  36.         if (!fst) res += ", ";
  37.         fst = 0; res += ts(x);
  38.     }
  39.     res += "}"; return res;
  40. }
  41. template<class A, class B> str ts(pair<A,B> p) {
  42.     return "("+ts(p.f)+", "+ts(p.s)+")"; }
  43. void DBG() { cerr << "]" << endl; }
  44. template<class H, class... T> void DBG(H h, T... t) {
  45.     cerr << ts(h); if (sizeof...(t)) cerr << ", ";
  46.     DBG(t...); }
  47.  
  48. #ifdef LOCAL
  49. #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
  50. #else
  51. #define dbg(...) 0
  52. //freopen(".in", "r", stdin);
  53. //freopen(".out", "w", stdout);
  54. #endif
  55. //CODE STARTS HERE-----------------------------------------------------------------------------------------//
  56. const int N = 21;
  57. int n;
  58. char a[N][N];
  59. queue<array<int, 6>> bfs;
  60. int vis[N][N][N][N][4][4],d[N][N][N][N][4][4];
  61. int dx[] = {0,1,0,-1}; int dy[] = {1,0,-1,0};
  62. array<int, 6> forward(array<int, 6> q){
  63.     array<int,6> ne = q;
  64.     ne[0] += dx[ne[4]];
  65.     ne[1] += dy[ne[4]];
  66.     ne[2] += dx[ne[5]];
  67.     ne[3] += dy[ne[5]];
  68.     if(a[ne[0]][ne[1]] == 'H' || ne[0] < 0 || ne[0] >= n || ne[1] < 0 || ne[1] >= n){
  69.         ne[0] -= dx[ne[4]];
  70.         ne[1] -= dy[ne[4]];
  71.     }
  72.     if(a[ne[2]][ne[3]] == 'H'|| ne[2] < 0 || ne[2] >= n || ne[3] < 0 || ne[3] >= n){
  73.         ne[2] -= dx[ne[5]];
  74.         ne[3] -= dy[ne[5]];
  75.     }
  76.     if(q[0] == 0 && q[1] == 0){
  77.         ne[0] = q[0], ne[1] = q[1];
  78.     }
  79.     if(q[2] == 0 && q[3] == 0){
  80.         ne[2] = q[2], ne[3] = q[3];
  81.     }
  82.     return ne;
  83. }
  84. vector<array<int, 6>> FIND(array<int,6> q){
  85.     vector<array<int, 6>> ret;
  86.     array<int, 6> ne = forward(q);
  87.     if(!vis[ne[0]][ne[1]][ne[2]][ne[3]][ne[4]][ne[5]]){
  88.         ret.pb(ne);
  89.         vis[ne[0]][ne[1]][ne[2]][ne[3]][ne[4]][ne[5]] = 1;
  90.     }
  91.     ne = q;
  92.     ne[4] = (q[4] + 1) % 4;
  93.     ne[5] = (q[5] + 1) % 4;
  94.     if(!vis[ne[0]][ne[1]][ne[2]][ne[3]][ne[4]][ne[5]]){
  95.         ret.pb(ne);
  96.         vis[ne[0]][ne[1]][ne[2]][ne[3]][ne[4]][ne[5]] = 1;
  97.     }
  98.     ne = q;
  99.     ne[4] = (q[4] + 3) % 4;
  100.     ne[5] = (q[5] + 3) % 4;
  101.     if(!vis[ne[0]][ne[1]][ne[2]][ne[3]][ne[4]][ne[5]]){
  102.         ret.pb(ne);
  103.         vis[ne[0]][ne[1]][ne[2]][ne[3]][ne[4]][ne[5]] = 1;
  104.     }
  105.     // dbg(ret);
  106.     return ret;
  107. }
  108. signed main(){
  109.     cin.tie(nullptr);
  110.     ios_base::sync_with_stdio(false);
  111.     // ifstream cin("cownav.in");
  112.     // ofstream cout("cownav.out");
  113.     cin >> n;
  114.     for(int i =0 ; i < n; i++){
  115.         for(int j =0 ; j < n; j++){
  116.             cin >> a[i][j];
  117.         }
  118.     }
  119.     bfs.push({n-1,n-1,n-1,n-1,2,3});
  120.     vis[n-1][n-1][n-1][n-1][2][3] = 1;
  121.     memset(d, 0x3f, sizeof(d));
  122.     d[n-1][n-1][n-1][n-1][2][3] = 0;
  123.     //0=up,1=right,2=down,3=left
  124.     while(!bfs.empty()){
  125.         array<int, 6> cur = bfs.front();
  126.         // dbg(cur,d[cur[0]][cur[1]][cur[2]][cur[3]][cur[4]][cur[5]]);
  127.         bfs.pop();
  128.         vector<array<int, 6>> remain = FIND(cur);
  129.         for(auto x : remain){
  130.             bfs.push(x);
  131.             d[x[0]][x[1]][x[2]][x[3]][x[4]][x[5]] = d[cur[0]][cur[1]][cur[2]][cur[3]][cur[4]][cur[5]] + 1;
  132.         }
  133.     }
  134.     int ans = 1e9;
  135.     for(int i = 0; i < 4; i++){
  136.         for(int j = 0; j < 4; j++){
  137.             ans = min(d[0][0][0][0][i][j],ans);
  138.         }
  139.     }
  140.     cout << ans << nl;
  141. }
Add Comment
Please, Sign In to add comment