Submission #263550

#TimeUsernameProblemLanguageResultExecution timeMemory
263550SortingBoard (CEOI13_board)C++17
70 / 100
1093 ms896 KiB
#include <bits/stdc++.h> using namespace std; string a, b; string get_path(const string &s){ string ans = ""; int n = s.size(); for(int i = 0; i < n; ++i){ if(s[i] == '1' || s[i] == '2') ans.push_back(s[i]); else{ if(s[i] == 'U') ans.pop_back(); else{ if(s[i] == 'L'){ for(int j = (int)ans.size() - 1; j >= 0; --j){ if(ans[j] == '2'){ ans[j] = '1'; for(int k = j + 1; k < (int)ans.size(); ++k) ans[k] = '2'; break; } } } else if(s[i] == 'R'){ for(int j = (int)ans.size() - 1; j >= 0; --j){ if(ans[j] == '1'){ ans[j] = '2'; for(int k = j + 1; k < (int)ans.size(); ++k) ans[k] = '1'; break; } } } } } } return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> a >> b; a = get_path(a); b = get_path(b); int x = a.size() + b.size(); int dist = 0, ans = x; bool ok = false; for(int i = 0; i < min(a.size(), b.size()); ++i){ if(a[i] != b[i] && !ok){ ok = true; if(a[i] == '2') swap(a, b); } dist = 2 * dist - 1; if(a[i] == '1') dist++; if(b[i] == '2') dist++; if(dist > 3) break; ans = min(ans, dist + x - 2 * (i + 1)); } cout << ans << "\n"; }

Compilation message (stderr)

board.cpp: In function 'int main()':
board.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   55 |     for(int i = 0; i < min(a.size(), b.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...