QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#297092#7965. 机器人FamiglistmoRE 0ms0kbC++173.8kb2024-01-03 22:40:132024-01-03 22:40:13

Judging History

你现在查看的是最新测评结果

  • [2024-01-03 22:40:13]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-01-03 22:40: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(){};
    Item(int h,int x,int y,int op,int replace_id,int trigger_op,int trigger_id):
        h(h),x(x),y(y),op(op),replace_id(replace_id),trigger_op(trigger_op),trigger_id(trigger_id){}
}item[N];
int p_cmd[105][15],p_robot[105][2];
string s;
int n,m,k,cnt;

int readin(){
    string s;
    cin>>s;
    int h,x,y,z;
    int cur=++cnt,id;
    if(s=="SLACKOFF") item[cur]=Item(-1,-1,-1,1,-1,-1,-1);
    if(s=="MOVE") cin>>h>>z,item[cur]=Item(h,z,-1,2,-1,-1,-1);
    if(s=="SWAP") cin>>h>>x>>y,item[cur]=Item(h,x,y,3,-1,-1,-1);
    if(s=="MIRROR") cin>>h>>x,item[cur]=Item(h,x,-1,4,-1,-1,-1);
    if(s=="REPLACE") cin>>h>>x,id=readin(),item[cur]=Item(h,x,-1,5,id,-1,-1);
    if(s=="ACTIVATE") cin>>h,item[cur]=Item(h,-1,-1,6,-1,-1,-1);
    if(s=="TRIGGER") {
        string t; cin>>t,id=readin();
        int op;
        if(t=="SLACKOFF:")op=1;
        if(t=="MOVE:")op=2;
        if(t=="SWAP:")op=3;
        if(t=="MIRROR:")op=4;
        if(t=="REPLACE:")op=5;
        if(t=="ACTIVATE:")op=6;
        if(t=="TRIGGER:")op=7;
        item[cur]=Item(-1,-1,-1,7,-1,op,id);
    }
    return cur;
}

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";
    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";
    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";
    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";
    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";
    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);
    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();
    }

    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...

result: