QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#522749 | #7104. Halting Problem | mhw# | AC ✓ | 69ms | 5764kb | C++20 | 2.3kb | 2024-08-17 13:08:19 | 2024-08-17 13:08:19 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pii make_pair
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=b;i>=a;--i)
using namespace std;
inline ll read() {
ll 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;
}
inline void print(ll x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) print(x / 10);
putchar(x % 10 + '0');
return ;
}
const int mod = 256;
inline void pprint(ll x) {
print(x);
puts("");
}
const int N = 2e5 + 7;
struct Node {
int opt;
int x, y;
} a[N];
string s;
int vis[N];
int n;
void slv() {
int cnt = 0;
int now = 1;
ll r = 0;
for(int cnt = 1; cnt <= n * 361; ++cnt){
if(now == n + 1){
puts("Yes");
return ;
}
// cout << "r = " << r << ", now = " << now << endl;
if(a[now].opt == 1) {
r = (r + a[now].x) % mod;
now = now + 1;
continue;
}
else if(a[now].opt == 2) {
if(r == a[now].x) {
now = a[now].y;
} else {
now = now + 1;
}
}
else if(a[now].opt == 3){
if(r != a[now].x){
now = a[now].y;
}else{
now = now + 1;
}
}
else if(a[now].opt == 4){
if(r < a[now].x){
now = a[now].y;
}else{
now = now + 1;
}
}
else if(a[now].opt == 5){
if(r > a[now].x){
now = a[now].y;
}else{
now = now + 1;
}
}
}
if(now == n + 1){
puts("Yes");
}else{
puts("No");
}
}
int main() {
int T = read();
while(T--) {
n = read();
for(int i = 1; i <= n; ++i) {
cin >> s;
if(s == "add") {
a[i].opt = 1;
a[i].x = read();
}
if(s == "beq") {
a[i].opt = 2;
a[i].x = read();
a[i].y = read();
}
if(s == "bne") {
a[i].opt = 3;
a[i].x = read();
a[i].y = read();
}
if(s == "blt") {
a[i].opt = 4;
a[i].x = read();
a[i].y = read();
}
if(s == "bgt") {
a[i].opt = 5;
a[i].x = read();
a[i].y = read();
}
}
// for(int i = 1; i <= n; ++i)
// cout << a[i].opt << " " << a[i].x << " " << a[i].y << endl;
slv();
}
return 0;
}
/*
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
*/
/*
4
*/
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5668kb
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: 69ms
memory: 5764kb
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