Submission #320519

#TimeUsernameProblemLanguageResultExecution timeMemory
320519monus1042Board (CEOI13_board)C++17
0 / 100
1098 ms170248 KiB
// NK #include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> using namespace std; //using namespace __gnu_pbds; typedef pair<int,int> ii; typedef long long ll; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<ll> vll; #define pb push_back #define eb emplace_back #define pob pop_back #define psf push_front #define pof pop_front #define mkp make_pair #define mkt make_tuple #define all(x) x.begin(), x.end() #define Bolivia_is_nice ios::sync_with_stdio(false), cin.tie(nullptr) //typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ord_set; ll locationof(string s, ll nod){ for (int i=0; i<s.size(); i++){ if (s[i] == '1'){ nod = nod*2; }else if (s[i] == '2'){ nod = nod*2 + 1; }else if (s[i] == 'U'){ nod = nod / 2; }else if (s[i] == 'L'){ nod = nod - 1; }else{ // R nod = nod + 1; } } return nod; } void solve(){ string a,b; cin>>a>>b; ll A = locationof(a, 1ll), B = locationof(b, 1ll); ll MAXsteps = 50 * 2 + 2; ll Log = 60; queue< pair<ll, ll> > bfs; // node, distance bfs.push(mkp(A,0)); set<ll> vis; vis.insert(A); while(true){ ll u = bfs.front().first; ll d = bfs.front().second; //cout<<u<<' '<<d<<endl; bfs.pop(); if (u == B){ cout<<d<<'\n'; return; } ll left, right, L, R, U; left = u*2; right = u*2 + 1LL; L = u-1; R = u+1; U = u/2; if (left < (ll)(1LL << Log) && vis.find(left) == vis.end() && d+1LL < MAXsteps){ vis.insert(left); bfs.push(mkp(left, d + 1LL)); } if (right < (ll)(1LL << Log) && vis.find(right) == vis.end() && d+1LL < MAXsteps){ vis.insert(right); bfs.push(mkp(right, d + 1LL)); } if (L < (ll)(1LL << Log) && vis.find(L) == vis.end() && d+1LL < MAXsteps){ ll cnt = 0; for (ll bit = Log; bit >= 0; --bit){ if (u & (1LL << bit)) ++cnt; } if (cnt != 1){ vis.insert(L); bfs.push(mkp(L, d + 1LL)); } } if (R < (ll)(1LL << Log) && vis.find(R) == vis.end() && d+1LL < MAXsteps){ bool sw = 0, ok = 1; for (ll bit = Log; bit >= 0; --bit){ if (u & (1LL << bit) && !sw){ sw = 1; }else if ( !(u & (1LL << bit)) && sw){ ok = 0; } } if (!ok){ vis.insert(R); bfs.push(mkp(R, d + 1LL)); } } if (U < (ll)(1LL << Log) && vis.find(U) == vis.end() && d+1LL < MAXsteps && U > 0LL){ vis.insert(U); bfs.push(mkp(U, d + 1LL)); } } } int main(){ Bolivia_is_nice; int t = 1; //cin>>t; while(t--) solve(); return 0; } /* ~/.emacs */

Compilation message (stderr)

board.cpp: In function 'll locationof(std::string, ll)':
board.cpp:28:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for (int i=0; i<s.size(); i++){
      |                ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...