QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#791583#9551. The Emperorucup-team5217WA 0ms3868kbC++232.8kb2024-11-28 19:41:412024-11-28 19:41:49

Judging History

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

  • [2024-11-28 19:41:49]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3868kb
  • [2024-11-28 19:41:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define int long long
int fa[2010];
int siz[2010];
const ll M=998244353;
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)   {fa[i]=0;siz[i]=0;}
    vector<string> s(n+1);
    vector<bool> ex(n+1);
    for(int i=0;i<=n;i++)  getline(cin, s[i]);
    vector<array<int,4>> mp(n+1);
    auto getf=[&](string & s,int pz)->pair<int,int> {
        int ans=0;
        while(pz<(int)s.size()){
            if(s[pz]<='9'&&s[pz]>='0')  ans=ans*10+s[pz++]-'0';
            else break;
        }
        return {ans,pz};
    };
    for(int i=1;i<=n;i++){
        if(s[i].substr(0,4)=="HALT"){
            pair<int,int> w1=getf(s[i],11);
            pair<int,int> w2=getf(s[i],w1.second+6);
            mp[i]={-1,-1,w1.first,w2.first};
        }
        else{
            pair<int,int> w1=getf(s[i],4);
            pair<int,int> w2=getf(s[i],w1.second+6);
            pair<int,int> w3=getf(s[i],w2.second+7);
            pair<int,int> w4=getf(s[i],w3.second+6);
            mp[i]={w1.first,w2.first,w3.first,w4.first};
        }
    }
    vector<array<int,3>> stk;//num,ope,pz
    int pz=1;
    vector<bool> flag(n+1);
    int pre=-1;
    ll ans=1;int tot=0;
    while (1){
        // cerr<<"___\n";
        // cerr<<pz<<'\n';
        // for(auto [x,y,z]:stk){
        //     cerr<<x<<' '<<y<<' '<<z<<'\n';
        // }
        // cerr<<"go!!!!!\n";
        // for(int i=1;i<=n;i++)   cerr<<flag[i]<<' ';
        // cerr<<'\n';
        // cerr<<"___\n";
        // cerr<<'\n';
        int pre=pz;
        bool fm=false;
        while(1){
            if(flag[pz])    {cout<<"-1\n";return ;}
            if(stk.empty()&&mp[pz][0]==-1){
                cout<<(ans%M+M)%M<<'\n';
                return ;
            }
            if(!stk.empty()&&stk.back()[0]==mp[pz][0]){
                ans=(ans+1)%M;
                if(mp[pz][1]==stk.back()[2]){
                    cout<<"-1\n";return ;
                }
                if(fa[stk.back()[2]]==0){
                    fa[stk.back()[2]]=mp[pz][1];
                    siz[stk.back()[2]]=(ans-stk.back()[1]+1)%M;        
                }
                flag[stk.back()[2]]=0;
                pz=mp[pz][1];
                stk.pop_back();fm=true;
                break;
            }
            if(fa[pz]==0)   break;
            ans=(ans+siz[pz])%M;
            pz=fa[pz];
            if(pz==pre){
                cout<<"-1\n";
                return ;
            }
        }
        if(!fm){
            ans=(ans+1)%M;
            stk.push_back({mp[pz][2],ans,pz});
            flag[pz]=1;
            pz=mp[pz][3];
        }
    }
    
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int _ =1;
    // cin>>_;
    while(_--) solve();
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

input:

1
HALT; PUSH 1 GOTO 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

5
POP 1 GOTO 2; PUSH 1 GOTO 2
HALT; PUSH 1 GOTO 3
POP 1 GOTO 4; PUSH 2 GOTO 4
POP 1 GOTO 2; PUSH 2 GOTO 4
HALT; PUSH 99 GOTO 4

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

1
POP 1 GOTO 1; PUSH 1 GOTO 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

61
POP 62 GOTO 61; PUSH 30 GOTO 60
POP 1 GOTO 3; PUSH 62 GOTO 61
POP 2 GOTO 61; PUSH 62 GOTO 61
POP 4 GOTO 7; PUSH 2 GOTO 61
POP 62 GOTO 61; PUSH 3 GOTO 4
POP 62 GOTO 61; PUSH 3 GOTO 5
POP 5 GOTO 10; PUSH 3 GOTO 6
POP 62 GOTO 61; PUSH 4 GOTO 7
POP 62 GOTO 61; PUSH 4 GOTO 8
POP 6 GOTO 12; PUSH 4 GOTO...

output:

150994941

result:

ok 1 number(s): "150994941"

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3868kb

input:

60
POP 1 GOTO 2; PUSH 1 GOTO 1
POP 51 GOTO 3; PUSH 51 GOTO 2
POP 2 GOTO 4; PUSH 2 GOTO 1
POP 52 GOTO 5; PUSH 52 GOTO 4
POP 3 GOTO 6; PUSH 3 GOTO 1
POP 53 GOTO 7; PUSH 53 GOTO 6
POP 4 GOTO 8; PUSH 4 GOTO 1
POP 54 GOTO 9; PUSH 54 GOTO 8
POP 5 GOTO 10; PUSH 5 GOTO 1
POP 55 GOTO 11; PUSH 55 GOTO 10
POP ...

output:

-1

result:

wrong answer 1st numbers differ - expected: '150994941', found: '-1'