//#include #include #include #include #include #include #include #include #include using namespace std; const int MAXN = 205; const int MAXP = 100005; const int INF = 1<<30; ifstream cin("party.in"); ofstream cout("party.out"); int consts[4][2]={{4, 400}, {3, 400}, {2, 400}, {1, 400}}; int FC, SC; struct Party { int x, y, t, w; Party(int x, int y, int t, int w) { this->x=x; this->y=y; this->t=t; this->w=w; } }; int n, p, k; int a[MAXN][MAXN]; int dist[MAXN][MAXN]; pair pred[MAXN][MAXN]; vector > s; vector party; int sys_time=0; long long cur_time=0; int homx, homy; int nop=0, last; int dir[4][2] = {{-1, 0}, {+1, 0}, {0, +1}, {0, -1}}; int bor[4][4]; bool cmp(Party p1, Party p2) { return p1.t+p1.w>n>>p>>k; Border(); for (int i=1; i<=n; i++) { for (int j=1; j<=n; j++) { cin>>a[i][j]; } } cin>>homx>>homy; for (int i=1; i<=p; i++) { int x, y, t, w; cin>>x>>y>>t>>w; party.push_back(Party(x, y, t, w)); } for (int i=1; i<=k; i++) { int x, y; cin>>x>>y; s.push_back(make_pair(x, y)); } stable_sort(party.begin(), party.end(), cmp); last=party[party.size()].t+party[party.size()].w; } void calcDist(int x, int y, int cakes) { for (int i=1; i<=n; i++) { for (int j=1; j<=n; j++) { dist[i][j]=INF; } } set > > q; q.insert(make_pair(0, make_pair(x, y))); dist[x][y]=0; pred[x][y]=make_pair(0, 0); while (!q.empty()) { pair > e=*q.begin(); q.erase(q.begin()); int t = e.first; int px = e.second.first; int py = e.second.second; for (int pos=0; pos<4; pos++) { if (px>bor[pos][0] and pxbor[pos][2] and pydist[px][py]+(dif+cakes)*(dif+cakes)+1) { dist[nx][ny] = dist[px][py]+(dif+cakes)*(dif+cakes)+1; pred[nx][ny] = make_pair(px, py); q.insert(make_pair(dist[nx][ny], make_pair(nx, ny))); } } } } } void nextStore(int * curx, int * cury, int * cakes) { calcDist(*curx, *cury, *cakes); int mint=INF; int minx, miny; for (int i=0; i st; int tx=minx; int ty=miny; while (true) { int nx=pred[tx][ty].first; int ny=pred[tx][ty].second; if (nx==0 or ny==0) break; if (nx+1==tx) st.push('D'); if (nx-1==tx) st.push('U'); if (ny+1==ty) st.push('R'); if (ny-1==ty) st.push('L'); tx=nx; ty=ny; } while (!st.empty()) { cout< cur_time + dist[e.x][e.y]) { cur_time = e.t+e.w; int tx = e.x; int ty = e.y; stack st; while (true) { int nx = pred[tx][ty].first; int ny = pred[tx][ty].second; if (nx==0 or ny==0) break; if (nx+1==tx) st.push('D'); if (nx-1==tx) st.push('U'); if (ny+1==ty) st.push('R'); if (ny-1==ty) st.push('L'); tx=nx; ty=ny; } while (!st.empty()) { cout<