QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#157087 | #7104. Halting Problem | ucup-team859# | AC ✓ | 85ms | 14248kb | C++14 | 1.6kb | 2023-09-02 14:54:25 | 2023-09-02 15:01:01 |
Judging History
answer
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
using ull = unsigned long long;
using ll = long long;
using namespace std;
struct command {
string s;
int x, y;
void init(string _s) {
s = _s;
if (s == "add") {
cin >> x;
} else {
cin >> x >> y;
y -= 1;
}
}
pair<int, int> exec(int l, int val) {
if (s == "add") {
val += x;
l += 1;
} else if (s == "beq") {
if (val == x)
l = y;
else
l += 1;
} else if (s == "bne") {
if (val != x)
l = y;
else
l += 1;
} else if (s == "blt") {
if (val < x)
l = y;
else
l += 1;
} else {
if (val > x)
l = y;
else
l += 1;
}
return make_pair(l, val);
}
};
const int NMAX = 2570004;
int test = 0;
int f[NMAX];
void solve() {
++test;
int n;
cin >> n;
vector<command> v;
for (int i = 1; i <= n; ++i) {
string s;
cin >> s;
command x;
x.init(s);
v.push_back(x);
}
int l = 0, val = 0;
while (1) {
if (l >= v.size()) {
cout << "Yes\n";
return;
}
tie(l, val) = v[l].exec(l, val);
val %= 256;
int state = l * 256 + val;
if (f[state] == test)
break;
f[state] = test;
}
cout << "No\n";
}
int main() {
#ifdef HOME
ifstream cin("input.in");
ofstream cout("output.out");
#endif
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3588kb
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: 85ms
memory: 14248kb
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