QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#169294#7104. Halting ProblemLilyWhite#AC ✓36ms4112kbC++143.7kb2023-09-09 13:18:012023-09-09 13:18:02

Judging History

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

  • [2023-09-09 13:18:02]
  • 评测
  • 测评结果:AC
  • 用时:36ms
  • 内存:4112kb
  • [2023-09-09 13:18:01]
  • 提交

answer

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
#define repn(i, n) for (int i = 1; i <= (int)n; i++)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repr(i, m, n) for (int i = (int)m; i <= (int)n; i++)
#define repd(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#ifdef LILYWHITE
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) ;
#endif
const int __attribute__((unused)) INF = 0x3f3f3f3f;
template <typename T> inline T rd(T &x) {
    x = 0;
    T neg = 1;
    char c = 0;
    while (c < '0' || c > '9') {
        if (c == '-')
            neg = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - 48;
        c = getchar();
    }
    x *= neg;
    return x;
}
template <typename T, typename... Args> inline void rd(T &x, Args &...args) {
    rd(x);
    rd(args...);
}
struct inst {
    int t,v,k;
    inst(int t, int v, int k):t(t),v(v),k(k){}
};
vector<inst> ins;
bitset<(10000 << 8) + 50> seen;
int main() {
    int tcs; rd(tcs);
    while (tcs--) {
        int n;
        rd(n);
        rep(i, n) {
            string cmd;
            cin >> cmd;
            if (cmd == "add") {
                int v;
                rd(v);
                ins.emplace_back(0, v, 0);
            } else if (cmd == "beq") {
                int v, k;
                rd(v, k); k--;
                ins.emplace_back(1, v, k);
            } else if (cmd == "bne") {
                int v, k;
                rd(v, k); k--;
                ins.emplace_back(2, v, k);
            } else if (cmd == "bgt") {
                int v, k;
                rd(v, k); k--;
                ins.emplace_back(3, v, k);
            } else if (cmd == "blt") {
                int v, k;
                rd(v, k); k--;
                ins.emplace_back(4, v, k);
            }
        }
        int r = 0, cur = 0;
        bool ans = 1;
        while (true) {
            auto curins = ins[cur];
            if (!seen[(cur << 8) + r]) seen.set((cur << 8) + r);
            else {
                // loop detected!
                ans = 0;
                break;
            }
            switch(curins.t) {
                case 0:
                    r = (r + curins.v) % 256;
                    cur++;
                    break;
                case 1:
                    if (r == curins.v) {
                        cur = curins.k;
                    } else cur++;
                    break;
                case 2:
                    if (r != curins.v) {
                        cur = curins.k;
                    } else cur++;
                    break;
                case 3:
                    if (r > curins.v) {
                        cur = curins.k;
                    } else cur++;
                    break;
                case 4:
                    if (r < curins.v) {
                        cur = curins.k;
                    } else cur++;
                    break;
            }
            if (cur >= n) break;
        }
        if (ans) puts("Yes"); else puts("No");
        seen.reset();
        ins.clear();
    }
}

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

詳細信息

Test #1:

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

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: 36ms
memory: 4044kb

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