QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#297077 | #7965. 机器人 | Famiglistmo | RE | 0ms | 0kb | C++17 | 5.5kb | 2024-01-03 22:24:42 | 2024-01-03 22:24:42 |
answer
#include<bits/stdc++.h>
using namespace std;
const int N=6e5+5;
struct Item{
int h,x,y,op;
int replace_id;
int trigger_op,trigger_id;
}item[N];
int p_cmd[105][15],p_robot[105][2];
string s;
int n,m,k,cnt,cur;
int getop(string& s){
if(s=="SLACKOFF")return 1;
if(s=="MOVE")return 2;
if(s=="SWAP")return 3;
if(s=="MIRROR")return 4;
if(s=="REPLACE")return 5;
if(s=="ACTIVATE")return 6;
if(s=="TRIGGER")return 7;
cout<<"QWQ\n",assert(0);
return 0;
}
int readin(){
cin>>s;
int h,x,y,z,id;
int cur=++cnt,op=getop(s),op2;
if(op==1) item[cur]=(Item){0,0,0,op,0,0,0};
if(op==2) cin>>h>>z,item[cur]=(Item){h,z,0,op,0,0,0};
if(op==3) cin>>h>>x>>y,item[cur]=(Item){h,x,y,op,0,0,0};
if(op==4) cin>>h>>x,item[cur]=(Item){h,x,0,op,0,0,0};
if(op==5) cin>>h>>x,id=readin(),item[cur]=(Item){h,x,0,op,id,0,0};
if(op==6) cin>>h,item[cur]=(Item){h,0,0,op,0,0,0};
if(op==7) cin>>s,s.pop_back(),op2=getop(s),id=readin(),item[cur]=(Item){0,0,0,op,0,op2,id};
return cur;
}
void output(int x){
if(item[x].op==1) cerr<<"SLACKOFF";
if(item[x].op==2) cerr<<"MOVE "<<item[x].h<<" "<<item[x].x;
if(item[x].op==3) cerr<<"SWAP "<<item[x].h<<" "<<item[x].x<<" "<<item[x].y;
if(item[x].op==4) cerr<<"MIRROR "<<item[x].h<<" "<<item[x].x;
if(item[x].op==5) cerr<<"REPLACE "<<item[x].h<<" "<<item[x].x<<" ",output(item[x].replace_id);
if(item[x].op==6) cerr<<"ACTIVATE "<<item[x].h;
if(item[x].op==7) {
cerr<<"TRIGGER ";
if(item[x].trigger_op==1) cerr<<"SLACKOFF: ";
if(item[x].trigger_op==2) cerr<<"MOVE: ";
if(item[x].trigger_op==3) cerr<<"SWAP: ";
if(item[x].trigger_op==4) cerr<<"MIRROR: ";
if(item[x].trigger_op==5) cerr<<"REPLACE: ";
if(item[x].trigger_op==6) cerr<<"ACTIVATE: ";
if(item[x].trigger_op==7) cerr<<"TRIGGER: ";
output(item[x].trigger_id);
}
}
void output(){
// for(int i=0;i<n;++i){
// cerr<<p_robot[i][0]<<" "<<p_robot[i][1]<<endl;
// for(int j=1;j<=m;++j)
// output(p_cmd[i][j]),cerr<<endl;
// }
// cerr<<"----\n";
}
void work(int i,int x,bool lst);
void findtrigger(int i,int op,bool lst);
void run(int i);
#define trigger(op) if(p_robot[i][1]^i) findtrigger(p_robot[i][1],op,lst)
void chk(){ if(++cur>k)exit(0); }
void slack(int id, int x, bool ist) {
chk();
printf("Robot %d slacks off.\n", id);
if (id != p_robot[id][1]) findtrigger(p_robot[id][1], 1, ist);
}
void move(int id, int x, bool ist) {
chk();
p_robot[id][item[x].h] = (p_robot[id][item[x].h] + item[x].x) % n;
if (!item[x].h) printf("Robot %d moves its left hand towards Robot %d.\n", id, p_robot[id][item[x].h]);
else printf("Robot %d moves its right hand towards Robot %d.\n", id, p_robot[id][item[x].h]);
if (id != p_robot[id][1]) findtrigger(p_robot[id][1], 2, ist);
}
void swap(int id, int x, bool ist) {
chk();
printf("Robot %d swaps a line of command with Robot %d.\n", id, p_robot[id][item[x].h]);
swap(p_cmd[p_robot[id][item[x].h]][item[x].x], p_cmd[id][item[x].y]);
if (id != p_robot[id][1]) findtrigger(p_robot[id][1], 3, ist);
}
void mirror(int id, int x, bool ist) {
chk();
printf("Robot %d modifies a line of command of Robot %d.\n", id, p_robot[id][item[x].h]);
if (item[p_cmd[p_robot[id][item[x].h]][item[x].x]].op != 0 && item[p_cmd[p_robot[id][item[x].h]][item[x].x]].op != 7)
item[p_cmd[p_robot[id][item[x].h]][item[x].x]].h ^= 1;
else if (item[p_cmd[p_robot[id][item[x].h]][item[x].x]].op == 7) {
item[++cnt] = item[item[p_cmd[p_robot[id][item[x].h]][item[x].x]].trigger_id];
item[cnt].h ^= 1;
item[p_cmd[p_robot[id][item[x].h]][item[x].x]].trigger_id = cnt;
}
if (id != p_robot[id][1]) findtrigger(p_robot[id][1], 4, ist);
}
void replace(int id, int x, bool ist) {
chk();
printf("Robot %d replaces a line of command of Robot %d.\n", id, p_robot[id][item[x].h]);
item[++cnt] = item[item[x].replace_id];
p_cmd[p_robot[id][item[x].h]][item[x].x] = cnt;
if (id != p_robot[id][1]) findtrigger(p_robot[id][1], 5, ist);
}
void activate(int i,int x,int lst){
chk();
printf("Robot %d activates Robot %d.\n", i, p_robot[i][item[x].h]);
run(p_robot[i][item[x].h]);
if (i != p_robot[i][1]) findtrigger(p_robot[i][1], 6, lst);
}
void work(int id, int x, bool ist) {
if (item[x].op == 1) slack(id, x, ist);
if (item[x].op == 2) move(id, x, ist);
if (item[x].op == 3) swap(id, x, ist);
if (item[x].op == 4) mirror(id, x, ist);
if (item[x].op == 5) replace(id, x, ist);
if (item[x].op == 6) activate(id, x, ist);
}
void findtrigger(int id, int tp, bool frm_ist) {
for (int i = 1; i <= m; i++) {
if (item[p_cmd[id][i]].op == 7) {
if (item[p_cmd[id][i]].trigger_op != 7 && item[p_cmd[id][i]].trigger_op == tp) {
work(id, item[p_cmd[id][i]].trigger_id, 1); break;
}
if (item[p_cmd[id][i]].trigger_op == 7 && frm_ist) {
work(id, item[p_cmd[id][i]].trigger_id, 1); break;
}
}
}
}
void run(int id) {
if (k == cur) exit(0);
for (int i = 1; i <= m; i++) {
work(id, p_cmd[id][i], 0);
}
}
signed main(){
// freopen("5.in","r",stdin);
// freopen("mine.out","w",stdout);
// ios::sync_with_stdio(false);
// cin.tie(0),cout.tie(0);
cin>>n>>m>>k;
for(int i=0;i<n;++i){
cin>>p_robot[i][0]>>p_robot[i][1];
for(int j=1;j<=m;++j)
p_cmd[i][j]=readin();
}
for(int cur=0;;++cur){
if(cur==n)cur=0;
run(cur);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
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...