QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#169475 | #7104. Halting Problem | chtholly3# | AC ✓ | 25ms | 17172kb | C++20 | 1.8kb | 2023-09-09 13:31:28 | 2023-09-09 13:31:29 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PII pair<int,int>
#define cp complex<double>
const int maxn = 1e5 + 10, maxm = 3e3 + 100;
const ll inf = 0x3f3f3f3f3f3f3f3f, mod = 1919810;
int a[maxn], suf[maxn];
string s;
int flag[maxn], v[maxn], k[maxn];
int vis[maxn][256];
void init(int n) {
n++;
for (int i = 0; i <= n; i++)
memset(vis[i], 0, sizeof(vis[i]));
}
void solve() {
int n;
cin >> n;
init(n);
for (int i = 1; i <= n; i++) {
cin >> s;
if (s == "add") {
flag[i] = 1;
cin >> v[i];
}
else {
if (s == "beq") flag[i] = 2;
else if (s == "bne") flag[i] = 3;
else if (s == "blt") flag[i] = 4;
else if (s == "bgt") flag[i] = 5;
cin >> v[i] >> k[i];
}
}
int now = 0, instr = 0, nextstr = 1;
int ans = 1;
while (1) {
//printf("%d: %d\n", instr, now);
instr = nextstr;
if (instr == n + 1) {
ans = 1;
break;
}
if (vis[instr][now]) {
ans = 0;
break;
}
vis[instr][now] = 1;
if (flag[instr] == 1) {
now = (now + v[instr]) % 256;
nextstr = instr + 1;
}
else if (flag[instr] == 2) { // beq
if (now == v[instr]) nextstr = k[instr];
else nextstr = instr + 1;
}
else if (flag[instr] == 3) { // bne
if (now != v[instr]) nextstr = k[instr];
else nextstr = instr + 1;
}
else if (flag[instr] == 4) { // ble
if (now < v[instr]) nextstr = k[instr];
else nextstr = instr + 1;
}
else if (flag[instr] == 5) { // bge
if (now > v[instr]) nextstr = k[instr];
else nextstr = instr + 1;
}
}
if (ans) cout << "Yes\n";
else cout << "No\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t; cin >> t;
while (t--) solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 5764kb
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: 25ms
memory: 17172kb
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