Submission #68929558
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define endl '\n'
using db = double;
template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
map<char, pair<LL, LL>> mp;
void init()
{
mp['U'] = {-1, 0};
mp['D'] = {1, 0};
mp['L'] = {0, -1};
mp['R'] = {0, 1};
}
LL sgn(LL x)
{
if (x > 0)
return 1;
if (x == 0)
return 0;
if (x < 0)
return -1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
init();
LL sx, sy, tx, ty;
cin >> sx >> sy >> tx >> ty;
tx -= sx, ty -= sy;
LL N, M, L;
cin >> N >> M >> L;
vector<pair<char, LL>> a(M), b(L);
for (int i = 0; i < M; ++i)
cin >> a[i].first >> a[i].second;
for (int i = 0; i < L; ++i)
cin >> b[i].first >> b[i].second;
vector<LL> cnta(M + 1), cntb(L + 1);
for (int i = 0; i < M; ++i)
{
cnta[i + 1] = cnta[i] + a[i].second;
}
for (int i = 0; i < L; ++i)
{
cntb[i + 1] = cntb[i] + b[i].second;
}
set<LL> st;
for (int i = 0; i <= M; ++i)
st.insert(cnta[i]);
for (int i = 0; i <= L; ++i)
st.insert(cntb[i]);
LL last = 0;
LL ans = 0;
st.erase(0);
for (auto now : st)
{
LL p1 = upper_bound(cnta.begin(), cnta.end(), last) - cnta.begin();
LL p2 = upper_bound(cntb.begin(), cntb.end(), last) - cntb.begin();
LL len = now - last;
char c1 = a[p1 - 1].first, c2 = b[p2 - 1].first;
LL dx = -mp[c1].first + mp[c2].first;
LL dy = -mp[c1].second + mp[c2].second;
// cerr << "-------" << endl;
// cerr << "now = " << now << " dx = " << dx << " dy = " << dy << endl;
// cerr << "p1 = " << p1 << " p2 = " << p2 << endl;
// cerr << "tx = " << tx << " ty = " << ty << " len = " << len << endl;
LL ndx = 0 - tx;
LL ndy = 0 - ty;
if (sgn(ndx) == sgn(dx) && sgn(ndy) == sgn(dy))
{
if (abs(dx) == 1 && abs(dy) == 1)
{
if (abs(dx) * len >= abs(ndx) && abs(dy) * len >= abs(ndy))
{
if (abs(ndy) == abs(ndx))
ans++;
}
}
else if (abs(dx) == 2 || abs(dy) == 2)
{
if (abs(dx) == 2)
{
if (abs(ndx) % 2 == 0 && len * abs(dx) >= abs(ndx))
ans++;
}
else if (abs(dy) == 2)
{
if (abs(ndy) % 2 == 0 && len * abs(dy) >= abs(ndy))
ans++;
}
}
else
{
if (ndx == 0 && ndy == 0)
ans += len;
}
}
last = now;
tx += dx * len;
ty += dy * len;
// cerr << "over : " << tx << " " << ty << endl;
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
D - RLE Moving |
User |
hialine |
Language |
C++ 20 (gcc 12.2) |
Score |
425 |
Code Size |
3147 Byte |
Status |
AC |
Exec Time |
71 ms |
Memory |
17204 KiB |
Compile Error
Main.cpp: In function ‘LL sgn(LL)’:
Main.cpp:29:1: warning: control reaches end of non-void function [-Wreturn-type]
29 | }
| ^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
425 / 425 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
All |
random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt |
Case Name |
Status |
Exec Time |
Memory |
random_01.txt |
AC |
71 ms |
17192 KiB |
random_02.txt |
AC |
43 ms |
11744 KiB |
random_03.txt |
AC |
17 ms |
6820 KiB |
random_04.txt |
AC |
26 ms |
8668 KiB |
random_05.txt |
AC |
11 ms |
5404 KiB |
random_06.txt |
AC |
67 ms |
16340 KiB |
random_07.txt |
AC |
67 ms |
16416 KiB |
random_08.txt |
AC |
67 ms |
16260 KiB |
random_09.txt |
AC |
70 ms |
17204 KiB |
random_10.txt |
AC |
70 ms |
17076 KiB |
random_11.txt |
AC |
68 ms |
17040 KiB |
random_12.txt |
AC |
71 ms |
16996 KiB |
random_13.txt |
AC |
70 ms |
16992 KiB |
random_14.txt |
AC |
69 ms |
17052 KiB |
random_15.txt |
AC |
47 ms |
12556 KiB |
random_16.txt |
AC |
47 ms |
12540 KiB |
random_17.txt |
AC |
66 ms |
17036 KiB |
random_18.txt |
AC |
67 ms |
17108 KiB |
random_19.txt |
AC |
65 ms |
17116 KiB |
random_20.txt |
AC |
66 ms |
17020 KiB |
sample_01.txt |
AC |
1 ms |
3636 KiB |
sample_02.txt |
AC |
1 ms |
3504 KiB |
sample_03.txt |
AC |
1 ms |
3516 KiB |
sample_04.txt |
AC |
1 ms |
3388 KiB |