# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1176462 | InvMOD | 게임판 (CEOI13_board) | C++20 | 2 ms | 1220 KiB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define gcd __gcd
#define sz(v) (int) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REV(i, a, b) for(int i = (a); i >= (b); i--)
#define dbg(x) "[" #x " = " << (x) << "]"
///#define int long long
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}
const int N = 2e5+5;
const ll MOD = 1e9+7;
const ll INF = 1e18;
void solve()
{
string s,t; cin >> s >> t;
auto conv = [&](const string &x) -> vector<int>{
// child position vs dad
vector<int> v;
for(const char &c : x){
if(c == '1' || c == '2')
v.pb((int) c - '0' - 1);
if(c == 'L' || c == 'R')
v.back() += (c == 'L' ? -1 : 1);
if(c == 'U'){
int val = v.back(); v.pop_back();
v.back() += (val / 2);
val -= (int)(val / 2) * 2;
if(val < 0) v.back()--;
}
}
for(int i = sz(v) - 1; i >= 1; i--){
int dif = v[i] / 2;
v[i] -= dif * 2;
if(v[i] < 0) dif--, v[i] += 2;
v[i - 1] += dif;
}
return v;
};
vector<int> A = conv(s), B = conv(t);
int dist = 0, ans = sz(A) + sz(B);
for(int i = 0; i < min(sz(A), sz(B)); i++){
dist += A[i] - B[i];
ans = min(ans, abs(dist) + sz(A) + sz(B) - 2 * (i + 1));
dist = dist * 2;
if(abs(dist) > 2 * (sz(A) + sz(B))) break;
}
cout << ans << "\n";
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP","r",stdin);
freopen(name".OUT","w",stdout);
}
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |