QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#246254#7104. Halting Problemucup-team2190#ML 1ms3540kbC++201.9kb2023-11-10 17:59:402023-11-10 17:59:41

Judging History

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

  • [2023-11-10 17:59:41]
  • 评测
  • 测评结果:ML
  • 用时:1ms
  • 内存:3540kb
  • [2023-11-10 17:59:40]
  • 提交

answer

/**
 *  - Meet Brahmbhatt
 *  - Hard work always pays off
**/
#include"bits/stdc++.h"
using namespace std;

#ifdef MeetBrahmbhatt
#include "debug.h"
#else
#define dbg(...) 72
#endif

#define endl "\n"
#define int long long

const long long INF = 4e18;

const int LOG = 256;

void solve() {
    int n;
    cin >> n;
    vector<string> t(n);
    vector<array<int, 2>> val(n);
    for (int i = 0; i < n; i++) {
        cin >> t[i];
        int x;
        cin >> x;
        if (t[i] == "add") {
            val[i] = {x, -1};
        } else {
            int y;
            cin >> y;
            val[i] = {x, y - 1};
        }
    }
    vector<vector<bool>> v(n + 1, vector<bool>(LOG));
    function<bool(int, int)> F = [&] (int id, int r) {
        if (id == n) {
            return true;
        }
        if (v[id][r]) {
            return false;
        }
        v[id][r] = 1;
        if (t[id] == "add") {
            return F(id + 1, (r + val[id][0]) % LOG);
        } else if (t[id] == "beq") {
            if (r == val[id][0]) {
                return F(val[id][1], r);
            } else {
                return F(id + 1, r);
            }
        } else if (t[id] == "bne") {
            if (r != val[id][0]) {
                return F(val[id][1], r);
            } else {
                return F(id + 1, r);
            }
        } else if (t[id] == "blt") {
            if (r < val[id][0]) {
                return F(val[id][1], r);
            } else {
                return F(id + 1, r);
            }
        } else {
            if (r > val[id][0]) {
                return F(val[id][1], r);
            } else {
                return F(id + 1, r);
            }
        }
    };
    cout << (F(0, 0) ? "Yes" : "No") << endl;
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    cout << fixed << setprecision(9);
    int tt = 1;
    cin >> tt;
    while (tt--) solve();
    return 0;
}

詳細信息

Test #1:

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

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: -100
Memory Limit Exceeded

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:


result: