QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#174807#7104. Halting Problemmendicillin2#AC ✓92ms4072kbC++171.7kb2023-09-10 13:32:242023-09-10 13:32:24

Judging History

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

  • [2023-09-10 13:32:24]
  • 评测
  • 测评结果:AC
  • 用时:92ms
  • 内存:4072kb
  • [2023-09-10 13:32:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

template <class T> int sz(T&& a) { return int(size(forward<T>(a))); }

template <class T> using vc = vector<T>;
template <class T> using vvc = vc<vc<T>>;

using ll = int64_t;
using vi = vc<int>;
using pii = pair<int, int>;
using uint = uint32_t;
using ull = uint64_t;

mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

template <class F>
struct ycr {
	F f;
	template <class T> explicit ycr(T&& f_) : f(forward<T>(f_)) {}

	template <class... Args> decltype(auto) operator()(Args&&... args) {
		return f(ref(*this), forward<Args>(args)...);
	}
};
template <class F> decltype(auto) yc(F&& f) {
	return ycr<decay_t<F>>(forward<F>(f));
}

bool solve() {
	int N; cin >> N;
	vector<string> OP(N);
	vector<int> V(N), K(N);
	for (int i = 0; i < N; i++) {
		cin >> OP[i];
		if (OP[i] == "add") {
			cin >> V[i];
		} else {
			cin >> V[i] >> K[i]; K[i]--;
		}
	}

	constexpr int X = 256;
	vector<bool> vis(N * X);
	return yc([&](auto self, int v, int r) -> bool {
		if (v == N) return true;
		int idx = v * X + r;
		if (vis[idx]) return false;
		vis[idx] = true;
		if (OP[v] == "add") {
			return self(v+1, (r+V[v]) & (X-1));
		} else if (OP[v] == "beq") {
			return r == V[v] ? self(K[v], r) : self(v+1, r);
		} else if (OP[v] == "bne") {
			return r != V[v] ? self(K[v], r) : self(v+1, r);
		} else if (OP[v] == "blt") {
			return r < V[v] ? self(K[v], r) : self(v+1, r);
		} else if (OP[v] == "bgt") {
			return r > V[v] ? self(K[v], r) : self(v+1, r);
		} else assert(false);
	})(0, 0);
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	cout << fixed << setprecision(20);

	int T; cin >> T;
	while (T--) {
		cout << (solve() ? "Yes" : "No") << '\n';
	}
}

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

詳細信息

Test #1:

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

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: 92ms
memory: 4072kb

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