QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#791134#9551. The Emperorucup-team5217#Compile Error//Python32.7kb2024-11-28 17:04:042024-11-28 17:04:05

Judging History

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

  • [2024-11-28 17:04:05]
  • 评测
  • [2024-11-28 17:04:04]
  • 提交

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;
int get(int x){
    if(fa[x]==x)    return x;
    int t=get(fa[x]);
    siz[x]=(siz[x]+siz[fa[x]])%M;
    return fa[x]=t;
}
void merge(int u,int f,ll len){
    fa[u]=f;siz[u]=len;
}
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)   {fa[i]=i;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};
        }
        // for(int j=0;j<4;j++)   cerr<<mp[i][j]<<' ';
        // cerr<<'\n';
    }
    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){
        // tot++;
        // cerr<<"!!!"<<fa[pz]<<' '<<fa[fa[pz]]<<' '<<fa[fa[fa[pz]]]<<'\n';
        // cerr<<"___\n";
        // cerr<<pz<<' '<<pre<<' '<<' '<<tot<<'\n';
        // for(auto [x,y,z]:stk){
        //     cerr<<x<<' '<<y<<' '<<z<<'\n';
        // }
        // cerr<<"___\n";
        if(pre!=-1)  {flag[pre]=0;pre=-1;}
        if(!stk.empty()&&mp[pz][0]==stk.back()[0]){
            pre=stk.back()[2];ans=(ans+1)%M;
            if(get(mp[pz][1])==stk.back()[2])   ex[stk.back()[2]]=1;
            else merge(stk.back()[2],mp[pz][1],(ans-stk.back()[1])%M);
            stk.pop_back();
            pz=mp[pz][1];
            continue;
        }
        int nxt=get(pz);
        if(mp[pz][0]==-1||mp[nxt][0]==-1){
            if(stk.size()==0){
                cout<<(ans%M+M)%M<<'\n';
                return ;
            }   
        }
        ans=(ans+siz[pz]+1)%M;
        if(flag[pz]||flag[nxt]||ex[pz]||ex[nxt])    {cout<<"-1\n";return ;}
        pz=nxt;
        int num=mp[pz][2];
        stk.push_back({num,ans,pz});
        flag[pz]=1;
        pz=mp[pz][3];
    }
    
}
signed main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int _ =1;
    // cin>>_;
    while(_--) solve();
}

详细

  File "answer.code", line 2
    using namespace std;
          ^^^^^^^^^
SyntaxError: invalid syntax