QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#296395 | #7965. 机器人 | Famiglistmo | RE | 0ms | 0kb | C++17 | 4.8kb | 2024-01-02 22:15:13 | 2024-01-02 22:15:13 |
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;
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;
puts("QWQ"),assert(0);
return 0;
}
int readin(int i){
cin>>s;
int h,x,y,z;
int cur=++cnt,op=getop(s);
if(op==1) item[cur]=(Item){-1,-1,-1,op,-1,-1,-1};
if(op==2) cin>>h>>z,item[cur]=(Item){h,z,-1,op,-1,-1,-1};
if(op==3) cin>>h>>x>>y,item[cur]=(Item){h,x,y,op,-1,-1,-1};
if(op==4) cin>>h>>x,item[cur]=(Item){h,x,-1,op,-1,-1,-1};
if(op==5) cin>>h>>x,item[cur]=(Item){h,x,-1,op,readin(i),-1,-1};
if(op==6) cin>>h,item[cur]=(Item){h,-1,-1,op,-1,-1,-1};
if(op==7) cin>>s,s.pop_back(),item[cur]=(Item){-1,-1,-1,op,-1,getop(s),readin(i)};
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(!k--)exit(0); }
void slack(int i,int x,bool lst){
chk();
cout<<"Robot "<<i<<" slacks off.\n";
output();
trigger(1);
}
void move(int i,int x,bool lst){
chk();
(p_robot[i][item[x].h]+=item[x].x)%=n;
cout<<"Robot "<<i<<" moves its "<<(item[x].h?"right":"left")<<" hand towards Robot "<<p_robot[i][item[x].h]<<".\n";
output();
trigger(2);
}
void swap(int i,int x,bool lst){
chk();
int j=p_robot[i][item[x].h];
swap(p_cmd[i][item[x].y],p_cmd[j][item[x].x]);
cout<<"Robot "<<i<<" swaps a line of command with Robot "<<j<<".\n";
output();
trigger(3);
}
void mirror(int i,int x,bool lst){
int j=p_robot[i][item[x].h];
int y=p_cmd[j][item[x].x];
chk();
if(item[y].op!=1&&item[y].op!=7) item[y].h^=1;
if(item[y].op==7)item[++cnt]=item[item[y].trigger_id],item[cnt].h^=1,item[y].trigger_id=cnt;
cout<<"Robot "<<i<<" modifies a line of command of Robot "<<j<<".\n";
output();
trigger(4);
}
void replace(int i,int x,int lst){
chk();
int j=p_robot[i][item[x].h];
item[++cnt]=item[item[x].replace_id];
p_cmd[j][item[x].x]=cnt;
cout<<"Robot "<<i<<" replaces a line of command of Robot "<<j<<".\n";
output();
trigger(5);
}
void activate(int i,int x,int lst){
chk();
int j=p_robot[i][item[x].h];
cout<<"Robot "<<i<<" activates Robot "<<j<<".\n";
run(j);
output();
trigger(6);
}
void work(int i,int x,bool lst){
int op=item[x].op;
if(op==1) slack(i,x,lst);
if(op==2) move(i,x,lst);
if(op==3) swap(i,x,lst);
if(op==4) mirror(i,x,lst);
if(op==5) replace(i,x,lst);
if(op==6) activate(i,x,lst);
}
void findtrigger(int i,int op,bool lst){
for(int k=1;k<=m;++k){
int x=p_cmd[i][k];
if(item[x].op==7){
bool fg=false;
if(item[x].trigger_op!=7&&item[x].trigger_op==op)fg=true;
if(item[x].trigger_op==7&&lst)fg=true;
if(fg) { work(i,item[x].trigger_id,1); break;}
}
}
}
void run(int i){
if(!k)exit(0);
for(int j=1;j<=m;++j)work(i,p_cmd[i][j],0);
}
signed main(){
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(i);
}
output();
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...