QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#160145#7104. Halting Problemucup-team134#AC ✓310ms232252kbC++143.3kb2023-09-02 19:35:262023-09-02 19:35:26

Judging History

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

  • [2023-09-02 19:35:26]
  • 评测
  • 测评结果:AC
  • 用时:310ms
  • 内存:232252kb
  • [2023-09-02 19:35:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define ll long long
typedef pair<ll,ll> pii;

const int mod=998244353;
inline int add(int x,int y){int ret=x+y;if(ret>=mod)ret-=mod;return ret;}
inline int sub(int x,int y){int ret=x-y;if(ret<0)ret+=mod;return ret;}
inline int mul(int x,int y){return ((ll)x*y)%mod;}
inline int step(int base,int pw){int ret=1;while(pw){if(pw&1)ret=mul(ret,base);base=mul(base,base);pw>>=1;}return ret;}
inline int invv(int x){return step(x,mod-2);}

const int maxn=3e6;
const int rsize=256;

vector<int>vect[maxn];
int pos[maxn];

void go(int x){


    pos[x]=1;
    for(int i=0;i<vect[x].size();i++){
        int id=vect[x][i];
        if(pos[id])continue;
        go(id);
    }
}

int main() {


    ///freopen("test.txt","r",stdin);

    int t;
    scanf("%d",&t);
    while(t--){

        int n;
        scanf("%d",&n);

        for(int i=0;i<=n;i++){
            for(int j=0;j<rsize;j++){
                vect[i*rsize+j].clear();
                pos[i*rsize+j]=0;
            }
        }

        for(int i=0;i<n;i++){

            string s;
            cin>>s;

            if(s=="add"){
                int x;
                scanf("%d",&x);
                for(int j=0;j<rsize;j++){
                    int nxt=(j+x)%rsize;
                    vect[i*rsize+j].pb((i+1)*rsize+nxt);
                }
            }
            else if(s=="beq"){
                int v,k;
                scanf("%d %d",&v,&k);
                k--;
                for(int j=0;j<rsize;j++){

                    if(j==v){
                        vect[i*rsize+j].pb(k*rsize+j);
                    }
                    else{
                        vect[i*rsize+j].pb((i+1)*rsize+j);
                    }

                }
            }
            else if(s=="bne"){
                int v,k;
                scanf("%d %d",&v,&k);
                k--;
                for(int j=0;j<rsize;j++){

                    if(j!=v){
                        vect[i*rsize+j].pb(k*rsize+j);
                    }
                    else{
                        vect[i*rsize+j].pb((i+1)*rsize+j);
                    }

                }
            }
            else if(s=="blt"){
                int v,k;
                scanf("%d %d",&v,&k);
                k--;
                for(int j=0;j<rsize;j++){

                    if(j<v){
                        vect[i*rsize+j].pb(k*rsize+j);
                    }
                    else{
                        vect[i*rsize+j].pb((i+1)*rsize+j);
                    }

                }
            }
            else if(s=="bgt"){
                int v,k;
                scanf("%d %d",&v,&k);
                k--;
                for(int j=0;j<rsize;j++){

                    if(j>v){
                        vect[i*rsize+j].pb(k*rsize+j);
                    }
                    else{
                        vect[i*rsize+j].pb((i+1)*rsize+j);
                    }

                }
            }

        }

        go(0);
        int e=0;
        for(int i=0;i<rsize;i++){
            e=max(e,pos[n*rsize+i]);
        }
        if(e)printf("Yes\n");
        else printf("No\n");

    }


    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 9ms
memory: 74920kb

input:

4
2
add 1
blt 5 1
3
add 252
add 1
bgt 252 2
2
add 2
bne 7 1
3
add 1
bne 252 1
beq 252 1

output:

Yes
Yes
No
No

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 310ms
memory: 232252kb

input:

1117
8
bgt 51 8
add 75
add 115
bne 40 3
beq 213 6
bgt 210 4
blt 228 7
bgt 60 2
6
bne 130 3
add 33
bne 74 4
blt 73 6
blt 63 5
bne 138 2
6
beq 131 2
bgt 90 3
add 127
bgt 195 1
blt 244 6
bne 20 3
3
add 53
bne 122 1
blt 251 2
9
add 102
add 161
bne 26 2
blt 5 8
beq 76 3
add 119
bgt 196 3
bne 239 8
blt 15...

output:

No
Yes
Yes
No
No
Yes
Yes
No
Yes
No
No
No
No
Yes
No
No
Yes
No
Yes
No
No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
No
No
Yes
No
Yes
No
No
No
Yes
No
No
No
No
No
Yes
No
Yes
Yes
Yes
No
Yes
No
Yes
No
Yes
No
No
No
No
Yes
No
No
Yes
No
No
Yes
No
No
No
Yes
Yes
Yes
Yes
No
Y...

result:

ok 1117 lines

Extra Test:

score: 0
Extra Test Passed