QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#555565#7104. Halting ProblemwxhtzdyTL 1ms3780kbC++171.4kb2024-09-10 04:48:262024-09-10 04:48:27

Judging History

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

  • [2024-09-10 04:48:27]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3780kb
  • [2024-09-10 04:48:26]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    vector<string> op(n);
    vector<int> v(n), k(n);
    for (int i = 0; i < n; i++) {
      cin >> op[i] >> v[i];
      if (op[i][0] == 'b') {
        cin >> k[i];
        --k[i];
      }
    }
    int p = 0, val = 0;
    set<pair<int, int>> st;
    bool ok = true;
    while (p < n) {
      if (st.find({val, p}) != st.end()) {
        ok = false;
        break;
      }
      st.insert({val, p});
      if (op[p] == "add") {
        val = (val + v[p]) % 256;
        p += 1;
        continue;
      }
      if (op[p] == "beq") {
        if (val == v[p]) {
          p = k[p];
        } else {
          p += 1;
        }
        continue;
      }
      if (op[p] == "bne") {
        if (val != v[p]) {
          p = k[p];
        } else {
          p += 1;
        }
        continue;
      }
      if (op[p] == "blt") {
        if (val < v[p]) {
          p = k[p];
        } else {
          p += 1;
        }
        continue;
      }
      if (op[p] == "bgt") {
        if (val > v[p]) {
          p = k[p];
        } else {
          p += 1;
        }
        continue;
      }
    }
    cout << (ok ? "Yes" : "No") << '\n';
  }
  return 0;
}

详细

Test #1:

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

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
Time 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: