# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
479891 |
2021-10-13T19:14:21 Z |
hidden1 |
Board (CEOI13_board) |
C++14 |
|
8 ms |
792 KB |
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
#define debug(...) cout << "Line: " << __LINE__ << endl; \
printDebug(", "#__VA_ARGS__, __VA_ARGS__)
template <typename T>
void printDebug(const char* name, T&& arg1) { cout << (name + 2) << " = " << arg1 << endl; }
template <typename T, typename... T2>
void printDebug(const char* names, T&& arg1, T2&&... args) {
const char* end = strchr(names + 1, ',');
cout.write(names + 2, end - names - 2) << " = " << arg1 << endl;
printDebug(end, args...);
}
// const ll MAX_N = 1e5 + 10;
const ll MAX_N = 60;
bitset<MAX_N> sum[2], diff[2];
void print(bitset<MAX_N> &a) {
for(ll i = 0; i < MAX_N; i ++) {
cout << a[i];
}
cout << endl;
}
void addPos(bitset<MAX_N> &nmb, ll pos) {
ll carry = 1;
while(carry && pos >= 0) {
if(nmb[pos]) {
nmb[pos] = nmb[pos] ^ bool(1);
} else {
nmb[pos] = nmb[pos] ^ bool(1);
carry = 0;
}
pos --;
}
}
void subPos(bitset<MAX_N> &nmb, ll pos) {
ll carry = 1;
while(carry && pos >= 0) {
if(nmb[pos]) {
nmb[pos] = nmb[pos] ^ bool(1);
carry = 0;
} else {
nmb[pos] = nmb[pos] ^ bool(1);
}
pos --;
}
}
bitset<MAX_N> asubb(bitset<MAX_N> &a, bitset<MAX_N> &b) {
bitset<MAX_N> ret;
for(ll i = 0; i < MAX_N; i ++) {ret[i] = 0;}
ll carry = 0;
ll pos = MAX_N - 1;
while(pos >= 0) {
ll val = ll(a[pos]) - ll(b[pos]) - carry;
if(val < 0) {
carry = 1;
} else {
carry = 0;
}
val = (val + 2) % 2;
ret[pos] = val;
pos --;
}
return ret;
}
signed main() {
// ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
string a, b;
cin >> a >> b;
sum[0][0] = 1;
sum[1][0] = 1;
ll levela = 0;
for(auto it : a) {
if(it == '1') {
levela ++;
} else if(it == '2') {
levela ++;
addPos(sum[0], levela);
} else if(it == 'L') {
addPos(diff[0], levela);
} else if(it == 'R') {
addPos(sum[0], levela);
} else if(it == 'U') {
levela --;
}
}
ll levelb = 0;
for(auto it : b) {
if(it == '1') {
levelb ++;
} else if(it == '2') {
levelb ++;
addPos(sum[1], levelb);
} else if(it == 'L') {
addPos(diff[1], levelb);
} else if(it == 'R') {
addPos(sum[1], levelb);
} else if(it == 'U') {
levelb --;
}
}
sum[0] = asubb(sum[0], diff[0]);
sum[1] = asubb(sum[1], diff[1]);
for(ll i = 0; i < MAX_N; i ++) {
if(sum[0][i] != sum[1][i]) {
if(sum[0][i]) {
swap(sum[0], sum[1]);
}
break;
}
}
ll dp = 0;
ll best = 4 * MAX_N;
for(ll i = 0; i <= min(levela, levelb); i ++) {
dp = (dp * 2ll);
if(sum[0][i] != sum[1][i]) {
if(sum[0][i]) {
dp --;
} else {
dp ++;
}
}
if(dp > 2 * best) {
break;
}
chkmin(best, dp + levela + levelb - 2 * i);
}
cout << best << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
288 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
716 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |