QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574730#7104. Halting Problemxuanbac05AC ✓118ms226592kbC++172.6kb2024-09-19 00:08:092024-09-19 00:08:09

Judging History

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

  • [2024-09-19 00:08:09]
  • 评测
  • 测评结果:AC
  • 用时:118ms
  • 内存:226592kb
  • [2024-09-19 00:08:09]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
 
using namespace std;
const int mxN = 5e5 + 227;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
 
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
    if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
    if (a < b) {a = b; return true;} return false;
}
 
struct Query{
    string op;
    int v, k;
} qr[mxN];

int n;
bool vis[mxN][256];

int add(int x, int y) {
    x += y;
    if(x >= 256) x -= 256;
    return x;
}

void dfs(int u, int k) {
    vis[u][k] = true;
        if(u == n + 1) return;
    if(qr[u].op == "add") {
        if(!vis[u + 1][add(k, qr[u].v)]) dfs(u + 1, add(k, qr[u].v));
    }
    if(qr[u].op == "beq") {
        if(k == qr[u].v) {
            if(!vis[qr[u].k][k]) dfs(qr[u].k, k);
        }
        else {
            if(!vis[u + 1][k]) dfs(u + 1, k);
        }
    }
    if(qr[u].op == "bne") {
        if(k != qr[u].v) {
            if(!vis[qr[u].k][k]) dfs(qr[u].k, k);
        }
        else {
            if(!vis[u + 1][k]) dfs(u + 1, k);
        }
    }
    if(qr[u].op == "blt") {
        if(k < qr[u].v) {
            if(!vis[qr[u].k][k]) dfs(qr[u].k, k);
        }
        else {
            if(!vis[u + 1][k]) dfs(u + 1, k);
        }
    }
    if(qr[u].op == "bgt") {
        if(k > qr[u].v) {
            if(!vis[qr[u].k][k]) dfs(qr[u].k, k);
        }
        else {
            if(!vis[u + 1][k]) dfs(u + 1, k);
        }
    }
}

 
void solve()
{
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> qr[i].op;
        if(qr[i].op == "add") cin >> qr[i].v;
        else cin >> qr[i].v >> qr[i].k;
    }

    for(int i = 0; i <= n + 7; i++)
    for(int j = 0; j < 256; j++) vis[i][j] = false;

    dfs(1, 0);

    bool res = false;
    for(int i = 0; i < 256; i++) res |= vis[n + 1][i];
    cout << (res == true ? "Yes" : "No") << endl;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // freopen(TASK".inp" , "r" , stdin);
    // freopen(TASK".out" , "w" , stdout);
 
    int tc = 1;
    cin >> tc;
    while(tc--) {
        solve();
    }
    return 0;
}

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

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 23328kb

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: 118ms
memory: 226592kb

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