#include #include #include #include #include "testlib.h" using i64 = long long; template using Pair = std::pair; template using Vec = std::vector; int main(int argc, char** argv) { registerTestlibCmd(argc, argv); while (true) { const i64 L = inf.readLong(); const int T = inf.readInt(); Vec> XDs(T); for (int i = 0; i < T; ++i) { XDs[i].first = inf.readLong(); inf.readSpace(); XDs[i].second = inf.readChar(); } if (L == 0 and T == 0) { break; } const i64 X0 = ouf.readLong(); const i64 V = ouf.readLong(); if (X0 < 0 or X0 >= L) { quitf(_wa, "X = %lld is out of range [0, %lld)", X0, L); } if (V <= 0 or V > L * 2) { quitf(_wa, "V = %lld is out of range [1, %lld]", V, L * 2); } Vec> nXDs; { constexpr const char* LR = "LR"; i64 X = X0; bool isRight = true; for (int t = 1; t <= T; t++) { if (isRight) { const i64 RD = L - X; if (V < RD) { X += V; } else if (V < RD + L) { X = L - (V - RD); isRight = false; } else { X = V - (RD + L); } } else { const i64 LD = X; if (V < LD) { X -= V; } else if (V < LD + L) { X = V - LD; isRight = true; } else { X = L - (V - (LD + L)); } } nXDs.emplace_back(X, LR[isRight]); } } std::sort(XDs.begin(), XDs.end()); std::sort(nXDs.begin(), nXDs.end()); if (XDs != nXDs) { std::cerr << "XDs: "; for (const auto& [X, D] : XDs) { std::cerr << "(" << X << ", " << D << ") "; } std::cerr << std::endl; std::cerr << "nXDs: "; for (const auto& [X, D] : nXDs) { std::cerr << "(" << X << ", " << D << ") "; } std::cerr << std::endl; quitf(_wa, "XDs != nXDs"); } } quitf(_ok, "OK"); return 0; }