# 【CF538G】Berserk Robot

## 题解

\begin{aligned} \begin{cases} p_i=\lfloor \frac {t_i}{l}\rfloor s_l+s_{t_i\ \bmod\ l}&(1)\\ p_j=\lfloor \frac {t_j}{l}\rfloor s_l+s_{t_j\ \bmod\ l}&(2)\\ 0\leq s_{t_j\ \bmod\ l}-s_{t_i\ \bmod\ l}\leq t_j\bmod l-t_i\bmod l \end{cases} \end{aligned}

\begin{aligned} (1)-(2): &p_i-p_j=\lfloor \frac {t_i}{l}\rfloor s_l+s_{t_i\ \bmod\ l}-\lfloor \frac {t_j}{l}\rfloor s_l-s_{t_j\ \bmod\ l}\\ \Leftrightarrow &(\lfloor \frac {t_i}{l}\rfloor-\lfloor \frac {t_j}{l}\rfloor)s_l=s_{t_j\ \bmod\ i}-s_{t_j\ \bmod\ l}+p_i-p_j \end{aligned}

$\therefore p_i-p_j\leq (\lfloor \frac {t_i}{l}\rfloor-\lfloor \frac {t_j}{l}\rfloor)s_l\leq p_i-p_j+t_j\bmod l-t_i\bmod l$

## 代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
LL gi() {
LL res = 0, w = 1;
char ch = getchar();
while (ch != '-' && !isdigit(ch)) ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar();
return res * w;
}
const int MAX_N = 2e6 + 5;
void Fail() { puts("NO"); exit(0); }
struct node { LL w, a, b; } a[MAX_N], b[MAX_N];
bool operator < (const node &l, const node &r) { return l.w < r.w; }
int N, L, dx[MAX_N], dy[MAX_N];
LL Floor(LL x, LL y) { return (x - (x % y + y) % y) / y; }
LL Ceil(LL x, LL y) { return (x + (y - x % y) % y) / y;  }
void solve(node p[], int q[]) {
sort(&p[1], &p[N + 1]);
LL l = 0, r = L;
for (int i = 0; i < N; i++) {
LL x = p[i].b - p[i + 1].b, k = p[i].a - p[i + 1].a, y = x + p[i + 1].w - p[i].w;
if (k > 0) l = max(l, Ceil(x, k)), r = min(r, Floor(y, k));
else if (k < 0) l = max(l, Ceil(y, k)), r = min(r, Floor(x, k));
else if (y < 0 || x > y) Fail();
}
if (l > r) Fail();
LL ls = 0, lw = 0;
for (int i = 1; i <= N; i++) {
LL s = p[i].b - l * p[i].a;
if (p[i].w == lw && s != ls) Fail();
for (int j = lw; j < lw + s - ls; j++) q[j] = 1;
ls = s, lw = p[i].w;
}
}
int main () {
#ifndef ONLINE_JUDGE
freopen("cpp.in", "r", stdin);
#endif
N = gi(), L = gi();
for (int i = 1; i <= N; i++) {
LL t = gi(), x = gi(), y = gi();
if ((x ^ y ^ t) & 1) Fail();
a[i] = (node){(int)(t % L), t / L, (x + y + t) / 2};
b[i] = (node){(int)(t % L), t / L, (x - y + t) / 2};
}
++N;
a[N] = (node){L, -1, 0};
b[N] = (node){L, -1, 0};
solve(a, dx);
solve(b, dy);
for (int i = 0; i < L; i++) putchar("LDUR"[dx[i] << 1 | dy[i]]);
putchar('\n');
return 0;
}

posted @ 2020-07-28 19:00  heyujun  阅读(215)  评论(2编辑  收藏  举报