QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#165581#7104. Halting Problem__mjjTL 188ms11304kbC++202.4kb2023-09-05 19:27:122023-09-05 19:27:12

Judging History

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

  • [2023-09-05 19:27:12]
  • 评测
  • 测评结果:TL
  • 用时:188ms
  • 内存:11304kb
  • [2023-09-05 19:27:12]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cstdio>
#include <queue>
#include <unordered_map>
#include <set>
#include <cmath>
#include <map>
#include <stack>
#include <sstream>
#include <random>
#include <ctime>
#include <chrono>
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define TIME cerr << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
#define debug(x) cerr << #x << " : " << x << '\n'
#define all(v) v.begin() , v.end()
// std::mt19937 rnd(std::chrono::system_clock::now().time_since_epoch().count());

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef pair<int , int> PII;

const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;

int read(){
    int x = 0 , f = 1;
    char c = getchar();
    while(c < '0' || c > '9'){
        if(c == '-')f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9'){
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

pair<string , PII> q[N];

void solve(){
    int n;
    cin >> n;
    for(int i = 1 ; i <= n ; i ++){
        string s;
        cin >> s;
        if(s == "add"){
            int x;
            cin >> x;
            q[i] = {s , {x , 0}};
        }else{
            int v , k;
            cin >> v >> k;
            q[i] = {s , {v , k}};
        }
    }
    int pos = 1 , cnt = 0 , val = 0;
    while(true){
        string s = q[pos].x;
        int a = q[pos].y.x , b = q[pos].y.y;
        if(s == "add"){
            pos ++;
            val = (val + a) % 256;
        }else if(s == "beq"){
            if(val == a)pos = b;
            else pos ++;
        }else if(s == "bne"){
            if(val != a)pos = b;
            else pos ++;
        }else if(s == "blt"){
            if(val < a)pos = b;
            else pos ++;
        }else{
            if(val > a)pos = b;
            else pos ++;
        }
        cnt ++;
        if(pos == n + 1)break;
        if(cnt >= cnt * 256)break;
    }
    if(pos == n + 1)puts("Yes");
    else puts("No");
}

int main(){
    int T;
    cin >> T;
    while(T --){
        solve();
    }
    return 0;
}
/* stuff you should look for
 * int overflow, array bounds
 * special cases (n=1?)
 * do smth instead of nothing and stay organized
 * WRITE STUFF DOWN
 * DON'T GET STUCK ON ONE APPROACH
 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 188ms
memory: 11304kb

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: -100
Time Limit Exceeded

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

result: