# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
272160 |
2020-08-18T10:00:01 Z |
johutha |
Board (CEOI13_board) |
C++17 |
|
118 ms |
10128 KB |
#include <iostream>
#include <vector>
#include <cassert>
#define int long long
using namespace std;
struct segtree
{
vector<pair<int,int>> table;
vector<int> op;
void apply(int pos, bool v)
{
if (v) swap(table[pos].first, table[pos].second);
op[pos] = op[pos] ^ v;
}
void propagate(int pos)
{
apply(2*pos + 1, op[pos]);
apply(2*pos + 2, op[pos]);
op[pos] = 0;
}
pair<int,int> merge(pair<int,int> p1, pair<int,int> p2)
{
return make_pair(max(p1.first, p2.first), max(p1.second, p2.second));
}
pair<int,int> query(int ql, int qr, int l, int r, int pos)
{
if (ql <= l && r <= qr) return table[pos];
if (r < ql || qr < l) return {-1ll, -1ll};
propagate(pos);
return merge(query(ql, qr, l, (l + r) / 2, 2*pos + 1), query(ql, qr, (l + r)/2 + 1, r, 2*pos + 2));
}
void set(int k, int v, int l, int r, int pos)
{
if (l == r)
{
table[pos] = make_pair((v == 0 ? l : -1ll), (v == 1 ? l : -1ll));
return;
}
propagate(pos);
if (k <= (l + r)/2) set(k, v, l, (l + r)/2, 2*pos + 1);
else set(k, v, (l + r)/2 + 1, r, 2*pos + 2);
table[pos] = merge(table[2*pos + 1], table[2*pos + 2]);
}
void update(int ql, int qr, int l, int r, int pos)
{
if (ql <= l && r <= qr) { apply(pos, 1); return; }
if (r < ql || qr < l) return;
propagate(pos);
update(ql, qr, l, (l + r)/2, 2*pos + 1);
update(ql, qr, (l + r)/2 + 1, r, 2*pos + 2);
table[pos] = merge(table[2*pos + 1], table[2*pos + 2]);
}
};
vector<bool> process(string ip)
{
int n = ip.size();
int cl = 0;
segtree st;
st.table.resize(4*n, {-1ll, -1ll});
st.op.resize(4*n, 0);
for (int i = 0; i < n; i++)
{
if (ip[i] == 'U') { st.set(cl - 1, -1, 0, n - 1, 0); cl--; }
else if (ip[i] == '1') { st.set(cl, 0, 0, n - 1, 0); cl++; }
else if (ip[i] == '2') { st.set(cl, 1, 0, n - 1, 0); cl++; }
else if (ip[i] == 'L')
{
int lr = st.query(0, n - 1, 0, n - 1, 0).second;
st.update(lr, cl - 1, 0, n - 1, 0);
}
else if (ip[i] == 'R')
{
int ll = st.query(0, n - 1, 0, n - 1, 0).first;
st.update(ll, cl - 1, 0, n - 1, 0);
}
}
vector<bool> res(cl);
for (int i = 0; i < cl; i++)
{
auto p = st.query(i, i, 0, n - 1, 0);
res[i] = (p.second == i);
}
return res;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
string ia, ib;
cin >> ia >> ib;
vector<bool> a = process(ia);
vector<bool> b = process(ib);
int ms = min((int)a.size(), (int)b.size());
for (int i = 0; i < ms; i++)
{
if (a[i] == b[i]) continue;
if (a[i]) { swap(a[i], b[i]); break; }
}
int dst = 0;
int res = 1e9;
for (int i = 0; i < ms; i++)
{
res = min(res, dst + (int)a.size() + (int)b.size() - 2*i);
dst *= 2;
dst += -1ll + (!a[i]) + (b[i]);
}
res = min(res, dst + (int)a.size() + (int)b.size() - 2*ms);
cout << res << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
7604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
2940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
4096 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
115 ms |
10116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
112 ms |
10128 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
118 ms |
9848 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |