QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#156713 | #7104. Halting Problem | ucup-team1321# | AC ✓ | 832ms | 153316kb | C++23 | 2.5kb | 2023-09-02 14:06:25 | 2023-09-02 14:52:00 |
Judging History
answer
#include <bits/stdc++.h>
#ifndef LOCAL
#define debug(...) 42
#endif
#define rep(i, x, y) for (int i = x; i < y; i++)
#define rp(i, n) rep(i, 0, n)
#define pb emplace_back
using namespace std;
template <typename T, typename T2> void cmin(T &x, const T2 &y) {
x = x < y ? x : y;
}
template <typename T, typename T2> void cmax(T &x, const T2 &y) {
x = x > y ? x : y;
}
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
template <class T> using vc = vector<T>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
mt19937 rng(time(NULL));
const int inf = 1000000000;
const ll lnf = 1000000000000000000;
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
void solve() {
int n;
cin>>n;
vc<array<int,3>> a(n);
rp(i,n){
string s;
cin>>s;
if(s=="add"){
int x;
cin>>x;
a[i]=array<int,3>{1,x,0};//r+=x
}else{
int x, k;
cin>>x>>k;
--k;
if(s=="beq"){
a[i]=array<int,3>{2,x,k};
}
if(s=="bne"){
a[i]=array<int,3>{3,x,k};
}
if(s=="blt"){
a[i]=array<int,3>{4,x,k};
}
if(s=="bgt"){
a[i]=array<int,3>{5,x,k};
}
}
}
// debug(a);
auto id=[&](int i,int j){
return i*256+j;
};
vc<vi> g((n+1)*256);
rp(i,n){
// debug(i,a[i]);
rp(j,256){
int u=id(i,j);
if(a[i][0]==1){
int v=id(i+1,(j+a[i][1])%256);
g[u].pb(v);
}
if(a[i][0]==2){
if(a[i][1]==j)g[u].pb(id(a[i][2],j));
else g[u].pb(id(i+1,j));
}
if(a[i][0]==3){
if(a[i][1]!=j)g[u].pb(id(a[i][2],j));
else g[u].pb(id(i+1,j));
}
if(a[i][0]==4){
if(j<a[i][1])g[u].pb(id(a[i][2],j));
else g[u].pb(id(i+1,j));
}
if(a[i][0]==5){
if(j>a[i][1])g[u].pb(id(a[i][2],j));
else g[u].pb(id(i+1,j));
}
}
}
// rp(i,(n+1)*256)if(sz(g[i]))debug(i,g[i]);
queue<int>q;
q.emplace(0);
vi d((n+1)*256,-1);
d[0]=0;
while(!q.empty()){
int u=q.front();q.pop();
// debug(u);
for(auto v:g[u]){
if(d[v]==-1){
d[v]=d[u]+1;
q.emplace(v);
}
}
}
bool ok=false;
rp(i,256)if(d[id(n,i)]!=-1)ok=true;
if(ok)cout<<"Yes\n";
else cout<<"No\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3724kb
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: 832ms
memory: 153316kb
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