QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#286456 | #7965. 机器人 | Renshey | TL | 0ms | 0kb | C++17 | 5.3kb | 2023-12-17 22:00:45 | 2023-12-17 22:00:46 |
answer
#include <bits/stdc++.h>
constexpr int maxn = 1 << 17;
const std::string d[2] = {"left", "right"};
int n, m, k, k_cnt, p[110][2]; double t_begin, t_end;
struct Op
{
std::string o; int h, x, y; std::string c;
Op (std::string _o = std::string(), int _h = 0, int _x = 0, int _y = 0, std::string _c = std::string()): o(_o), h(_h), x(_x), y(_y), c(_c) {}
} f[110][20];
void Print (int i)
{
// std::cerr << "------------" << i << "------------" << std::endl;
// for (int j = 1; j <= m; j++)
// {
// std::cerr << f[i][j].o << " " << f[i][j].h << " " << f[i][j].x << " " << f[i][j].y << " " << f[i][j].c << std::endl;
// }
// std::cerr << "------------------------" << std::endl;
}
void split (std::string &C, std::string &s)
{
int p = C.find_first_of(' ');
if (p == C.npos) s = C, C = std::string();
else s = C.substr(0, p), C = C.substr(p + 1);
}
Op GetString (std::string C)
{
// std::cerr << "get String [" << C << "]" << std::endl;
std::string s; split(C, s);
// std::cerr << "[" << s << "][" << C << "]" << std::endl;
// std::stringstream sin(C); //std::string s; sin >> s;
if (s == "SLACKOFF") return Op(s);
if (s == "MOVE" or s == "MIRROR") {return Op(s, C[0] - '0', std::atoi(C.substr(2).c_str()));}
if (s == "SWAP") {int h = C[0] - '0'; std::string x; split(C = C.substr(2), x); return Op(s, h, std::atoi(x.c_str()), std::atoi(C.c_str()));}
if (s == "REPLACE") {int h = C[0] - '0'; std::string x; split(C = C.substr(2), x); return Op(s, h, std::atoi(x.c_str()), 0, C);}
if (s == "ACTIVATE") {return Op(s, C[0] - '0');}
if (s == "TRIGGER") return Op(s, 0, 0, 0, C);
return Op();
}
void Output (const std::string &s)
{
std::cout << s << "\n";
if ((++k_cnt) == k)
{
t_end = clock();
std::cerr << (t_end - t_begin) / CLOCKS_PER_SEC << std::endl;
exit(0);
}
//Print(0); Print(41);
}
int inc (int &x, int y) {return (x += y) %= n;}
void Mirror (std::string &s) {for (char &c: s) if (c == '0' or c == '1') {c ^= 1; return;}}
void Activate (int i);
void Trigger (int i, std::string &s, int o)
{
// std::cerr << "TRIGGER!!! " << i << " " << s << std::endl;
// std::cerr << "Type of 41, 8 is " << Type(f[41][8].c) << std::endl;
for (int j = 1; j <= m; j++) if (f[i][j].o == "TRIGGER" and [&](){
int p = f[i][j].c.find_first_of(':');
auto c = f[i][j].c.substr(0, p);
return c == s or (c == "TRIGGER" and o);
}())
{
// std::cerr << "TRIGGER: " << i << " " << j << std::endl;
Op F = GetString(f[i][j].c.substr(f[i][j].c.find(' ') + 1)); auto T = F.o;
if (T == "SLACKOFF") Output("Robot " + std::to_string(i) + " slacks off.");
if (T == "MOVE") Output("Robot " + std::to_string(i) + " moves its " + d[F.h] + " hand towards Robot " + std::to_string(inc(p[i][F.h], F.x)) + ".");
if (T == "SWAP") Output("Robot " + std::to_string(i) + " swaps a line of command with Robot " + std::to_string(p[i][F.h]) + "."), std::swap(f[i][F.y], f[p[i][F.h]][F.x]);
if (T == "MIRROR")
{
Output("Robot " + std::to_string(i) + " modifies a line of command of Robot " + std::to_string(p[i][F.h]) + ".");
if (f[p[i][F.h]][F.x].o != "TRIGGER") f[p[i][F.h]][F.x].h ^= 1;
else Mirror(f[p[i][F.h]][F.x].c);
}
if (T == "REPLACE")
{
Output("Robot " + std::to_string(i) + " replaces a line of command of Robot " + std::to_string(p[i][F.h]) + ".");
f[p[i][F.h]][F.x] = GetString(F.c);
}
if (T == "ACTIVATE")
{
Output("Robot " + std::to_string(i) + " activates Robot " + std::to_string(p[i][F.h]) + ".");
Activate(p[i][F.h]);
}
if (T != "TRIGGER" and p[i][1] != i) Trigger(p[i][1], T, 1);
break;
}
// std::cerr << "TRIGGER END!!!" << std::endl;
}
void Activate (int i)
{
for (int j = 1; j <= m; j++)
{
auto T = f[i][j].o;
if (T == "SLACKOFF") Output("Robot " + std::to_string(i) + " slacks off.");
if (T == "MOVE") Output("Robot " + std::to_string(i) + " moves its " + d[f[i][j].h] + " hand towards Robot " + std::to_string(inc(p[i][f[i][j].h], f[i][j].x)) + ".");
if (T == "SWAP") Output("Robot " + std::to_string(i) + " swaps a line of command with Robot " + std::to_string(p[i][f[i][j].h]) + "."), std::swap(f[i][f[i][j].y], f[p[i][f[i][j].h]][f[i][j].x]);
if (T == "MIRROR")
{
Output("Robot " + std::to_string(i) + " modifies a line of command of Robot " + std::to_string(p[i][f[i][j].h]) + ".");
if (f[p[i][f[i][j].h]][f[i][j].x].o != "TRIGGER") f[p[i][f[i][j].h]][f[i][j].x].h ^= 1;
else Mirror(f[p[i][f[i][j].h]][f[i][j].x].c);
}
if (T == "REPLACE")
{
Output("Robot " + std::to_string(i) + " replaces a line of command of Robot " + std::to_string(p[i][f[i][j].h]) + ".");
f[p[i][f[i][j].h]][f[i][j].x] = GetString(f[i][j].c);
}
if (T == "ACTIVATE")
{
Output("Robot " + std::to_string(i) + " activates Robot " + std::to_string(p[i][f[i][j].h]) + ".");
Activate(p[i][f[i][j].h]);
}
if (T != "TRIGGER" and p[i][1] != i) Trigger(p[i][1], T, 0);
}
}
signed main ()
{
t_begin = clock();
std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
std::cin >> n >> m >> k; //k = 4;
for (int i = 0; i < n; i++)
{
std::cin >> p[i][0] >> p[i][1]; std::string s; getline(std::cin, s);
for (int j = 1; j <= m; j++) getline(std::cin, s), f[i][j] = GetString(s);
}
// Print(41);
for (int i = 0; true; i = (i + 1) % n) Activate(i);
return 0;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
100 1 300000 1 1 REPLACE 0 1 REPLACE 0 1 REPLACE 1 1 REPLACE 0 1 REPLACE 0 1 REPLACE 0 1 REPLACE 1 1 REPLACE 1 1 REPLACE 0 1 REPLACE 1 1 REPLACE 1 1 REPLACE 1 1 REPLACE 1 1 REPLACE 0 1 REPLACE 1 1 REPLACE 0 1 REPLACE 0 1 REPLACE 0 1 REPLACE 1 1 REPLACE 0 1 REPLACE 0 1 REPLACE 1 1 REPLACE 0 1 REPLACE...
output:
Robot 0 replaces a line of command of Robot 1. Robot 1 replaces a line of command of Robot 2. Robot 2 replaces a line of command of Robot 3. Robot 3 replaces a line of command of Robot 4. Robot 4 replaces a line of command of Robot 5. Robot 5 replaces a line of command of Robot 6. Robot 6 replaces a...