传送门
好像没用什么算法。。。
考虑把坐标 ( x , y ) → ( y + x , y − x ) (x,y)\rightarrow(y+x,y-x) (x,y)→(y+x,y−x)
然后每一步位移变成 ( + ‾ 1 , + ‾ 1 ) (\underline +1,\underline +1) (+1,+1)
再每步 x , y x,y x,y都额外 + 1 +1 +1后除以2
那每个信息的 ( x , y ) → ( ( x + y + t ) / 2 , ( y − x + t ) / 2 ) (x,y)\rightarrow((x+y+t)/2,(y-x+t)/2) (x,y)→((x+y+t)/2,(y−x+t)/2)
这样 x , y x,y x,y之间没有关联了
考虑对于 x x x
现在每一步要么不变要么 + 1 +1 +1
令 k k k为每一次总循环的位移, w = t % l , v = ⌊ t l ⌋ w=t\%l,v=\lfloor\frac {t}{l}\rfloor w=t%l,v=⌊lt⌋
按照 w w w排序后对于前后两个 i , j = i + 1 i,j=i+1 i,j=i+1
合法就必须满足 x j − x i ≤ k + Δ v ∗ k , x j − x i ≥ Δ v ∗ k x_j-x_i\le k+\Delta v*k,x_j-x_i\geq \Delta v*k xj−xi≤k+Δv∗k,xj−xi≥Δv∗k
移项后就得一个到 k k k的大小限制
得到所有的限制后取一个合法的 k k k再还原即可
#include
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair
#define ll long long
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline ll readll(){
char ch=gc();
ll res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
inline int readstring(char *s){
int top=0;char ch=gc();
while(isspace(ch))ch=gc();
while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
return top;
}
template<typename tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<typename tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int N=200005,M=2000005;
int n,l,vx[M],vy[M];
struct node{
ll x,y,t,w,v;
node(ll a=0,ll b=0,ll c=0,ll d=0,ll e=0):x(a),y(b),t(c),w(d),v(e){}
friend inline bool operator <(cs node &a,cs node &b){
return a.w<b.w;
}
}a[N];
inline void get(int *ans){
ll L=0,R=l;
for(int j=2;j<=n;j++){
ll dv=a[j].v-a[j-1].v,dw=a[j].w-a[j-1].w,dx=a[j].x-a[j-1].x;
if(dv==0){
if(dx<0||dx-dw>0){puts("NO");exit(0);}
}
if(dv>0){
chemx(L,(ll)ceil(1.0*(dx-dw)/dv)),chemn(R,(ll)floor(1.0*dx/dv));
}
if(dv<0){
chemx(L,(ll)ceil(1.0*dx/dv)),chemn(R,(ll)floor(1.0*(dx-dw)/dv));
}
}
if(L>R){puts("NO");exit(0);}
int k=L;
for(int i=2;i<=n;i++){
int dx=(a[i].x-a[i].v*k)-(a[i-1].x-a[i-1].v*k),del=a[i].w-a[i-1].w;
if(dx<0){puts("NO");exit(0);}
for(int j=1;j<=del;j++){
if(j<=dx)ans[j+a[i-1].w]=1;
else ans[j+a[i-1].w]=0;
}
}
}
int main(){
#ifdef Stargazer
freopen("lx.in","r",stdin);
#endif
n=read(),l=read();
for(int i=1;i<=n;i++){
ll t=readll(),x=readll(),y=readll();
if((x+y+t)&1)return puts("NO"),0;
if((x-y+t)&1)return puts("NO"),0;
a[i].x=(x+y+t)>>1,a[i].y=(y-x+t)>>1,a[i].t=t,a[i].w=t%l,a[i].v=t/l;
};
n++,a[n]=node(0,0,0,0,0),n++,a[n]=node(0,0,0,l,-1);
sort(a+1,a+n+1);
get(vx);
for(int i=1;i<=n;i++)swap(a[i].x,a[i].y);
get(vy);
for(int i=1;i<=l;i++){
if(vx[i]==0&&vy[i]==0)putchar('D');
if(vx[i]==0&&vy[i]==1)putchar('L');
if(vx[i]==1&&vy[i]==0)putchar('R');
if(vx[i]==1&&vy[i]==1)putchar('U');
}return 0;
}