Submission #320831

#TimeUsernameProblemLanguageResultExecution timeMemory
320831monus1042Board (CEOI13_board)C++17
100 / 100
5 ms1772 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; const int MAXS = 1e5 + 10; deque<int> Abin(MAXS), Bbin(MAXS); void helper(deque<int> & ops, int pos){ ops[pos - 1] += ops[pos] / 2; if (ops[pos] < 0 && ops[pos]%2 != 0){ ops[pos - 1]--; } ops[pos] = abs(ops[pos]) % 2; } void traverse(string s, deque<int> & ops){ int iter; ops[0] = iter = 1; for (int i=0; i<s.size(); i++){ if (s[i] == '1'){ ops[iter] = 0; iter++; }else if (s[i] == '2'){ ops[iter] = 1; iter++; }else if (s[i] == 'L'){ ops[iter - 1]--; }else if (s[i] == 'R'){ ops[iter - 1]++; }else{ // U helper(ops, iter - 1); iter--; } } for (int i=iter-1; i>=1; i--){ helper(ops, i); } while(ops.size() > iter) ops.pob(); while(ops.front() == 0) ops.pof(); } void solve(){ string a,b; cin>>a>>b; traverse(a, Abin); traverse(b, Bbin); if (Abin.size() < Bbin.size()) swap(Abin, Bbin); int ans, UB; ans = UB = MAXS * 2; int diff = Abin.size() - Bbin.size(); while(Abin.size() > Bbin.size()) Abin.pob(); int HOR = 0; for (int i=0; i<Abin.size(); i++){ HOR = HOR * 2 + Abin[i] - Bbin[i]; int current = diff + abs(HOR) + 2 * (int)(Abin.size() - i - 1); if (current >= UB) break; ans = min(ans, current); } cout<<ans<<'\n'; } int main(){ Bolivia_is_nice; int t = 1; //cin>>t; while(t--) solve(); return 0; } /* ~/.emacs */

Compilation message (stderr)

board.cpp: In function 'void traverse(std::string, std::deque<int>&)':
board.cpp:41:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (int i=0; i<s.size(); i++){
      |                ~^~~~~~~~~
board.cpp:60:19: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |  while(ops.size() > iter) ops.pob();
      |        ~~~~~~~~~~~^~~~~~
board.cpp: In function 'void solve()':
board.cpp:76:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for (int i=0; i<Abin.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...