QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#303855#7104. Halting Problemkevinshan#AC ✓52ms13688kbC++173.3kb2024-01-13 01:57:152024-01-13 01:57:15

Judging History

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

  • [2024-01-13 01:57:15]
  • 评测
  • 测评结果:AC
  • 用时:52ms
  • 内存:13688kb
  • [2024-01-13 01:57:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define ps push
#define in insert
#define f first
#define s second
#define nl cout<<"\n"
#define ca(v) for(auto i:v) cout<<i<<" ";
#define cbit(x) __builtin_popcount(x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a*b/gcd(a, b))
const int xm[4] = {-1, 1, 0, 0};
const int ym[4] = {0, 0, -1, 1};
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
const ll POW = 9973;

int vis[10005][256];
struct qry{
    int id;
    // add = 1, beq = 2, bne = 3, blt = 4, bgt = 5;
    int x;
    int to;
};
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }

    int t; cin>>t;
    while(t--){
        int n; cin>>n;
        vector<qry> mv;
        for(int i=0; i<n; i++){
            string s; cin>>s;
            int x; cin>>x;
            if(s == "add"){
                mv.pb({1, x, -1});
            } else {
                int to; cin>>to;
                to--;
                if(s == "beq"){
                    mv.pb({2, x, to});
                }
                else if(s == "bne"){
                    mv.pb({3, x, to});
                }
                else if(s == "blt"){
                    mv.pb({4, x, to});
                }
                else if(s == "bgt"){
                    mv.pb({5, x, to});
                }
            }
        }
        queue<pair<int, int>> q;
        q.push({0, 0});
        vis[0][0] = 1;
        while(q.size()){
            auto c = q.front();
            q.pop();
            int p = c.f;
            int x = c.s;
            if(p == n) break;
            pair<int, int> np = {-1, -1};
            if(mv[p].id == 1){
                np.f = p+1;
                np.s = (x + mv[p].x)% 256;
            }
            else if(mv[p].id == 2){
                if(x == mv[p].x){
                    np.f = mv[p].to;
                    np.s = x;
                } else {
                    np.f = p+1;
                    np.s = x;
                }
            }
            else if(mv[p].id == 3){
                if(x != mv[p].x){
                    np.f = mv[p].to;
                    np.s = x;
                } else {
                    np.f = p+1;
                    np.s = x;
                }
            }
            else if(mv[p].id == 4){
                if(x < mv[p].x){
                    np.f = mv[p].to;
                    np.s = x;
                } else {
                    np.f = p+1;
                    np.s = x;
                }
            }
            else if(mv[p].id == 5){
                if(x > mv[p].x){
                    np.f = mv[p].to;
                    np.s = x;
                } else {
                    np.f = p+1;
                    np.s = x;
                }
            }
            if(!vis[np.f][np.s]){
                vis[np.f][np.s] = 1;
                q.push(np);
            }
        }
        int valid = 0;
        for(int i=0; i<256; i++) valid += vis[n][i];
        if(valid) cout<<"Yes\n";
        else cout<<"No\n";
        for(int i=0; i<=n; i++) for(int j=0; j<256; j++) vis[i][j] = 0;
    }
}


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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3396kb

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: 52ms
memory: 13688kb

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