QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#182244 | #7104. Halting Problem | zipdang04# | AC ✓ | 125ms | 6520kb | C++14 | 4.0kb | 2023-09-17 15:30:10 | 2023-09-17 15:30:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
*/
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
template <class T> using PQMax = priority_queue<T>;
template <class T> using PQMin = priority_queue<T, vector<T>, greater<T>>;
template <class T1, class T2>
void maximize(T1 &a, T2 b){
if (b > a) a = b;
}
template <class T1, class T2>
void minimize(T1 &a, T2 b){
if (b < a) a = b;
}
template <class T>
void read(T &number)
{
bool negative = false;
register int c;
number = 0;
c = getchar();
while (c != '-' && !isalnum(c)) c = getchar();
if (c=='-'){
negative = true;
c = getchar();
}
for (; (c>47 && c<58); c=getchar())
number = number *10 + c - 48;
if (negative)
number *= -1;
}
template <class T, class ...Ts>
void read(T &a, Ts& ... args){
read(a);
read(args...);
}
/*
struct Node
{
int node, len;
Node() {node = len = 0;}
Node(int node, int len) {this -> node = node, this -> len = len;}
};
typedef vector<Node> vg;
*/
#define MAX 10005
#define MOD 256
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define FOR(type, i, a, b) for(type i = (a); i <= (b); i++)
#define FORD(type, i, b, a) for(type i = (b); i >= (a); i--)
#define testBit(n, bit) (((n) >> (bit)) & 1)
#define flipBit(n, bit) ((n) ^ (1ll << (bit)))
#define cntBit(n) __builtin_popcount(n)
#define cntBitll(n) __builtin_popcountll(n)
#define randomize mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
struct Instruction{
string instruction;
int v, k;
Instruction(){
instruction = "";
v = k = 0;
}
Instruction(string instruction, int v, int k){
this -> instruction = instruction;
this -> v = v;
this -> k = k;
}
};
struct State{
int value, position;
};
int n;
Instruction instructions[MAX];
bool visited[MOD][MAX] = {};
State process(State state, Instruction instruction){
if (instruction.instruction == "add"){
state.value += instruction.v; state.value %= MOD;
state.position++;
return state;
}
if (instruction.instruction == "beq")
state.position = (state.value == instruction.v ? instruction.k : state.position + 1);
else if (instruction.instruction == "bne")
state.position = (state.value != instruction.v ? instruction.k : state.position + 1);
else if (instruction.instruction == "blt")
state.position = (state.value < instruction.v ? instruction.k : state.position + 1);
else // if (instruction.instruction == "bgt")
state.position = (state.value > instruction.v ? instruction.k : state.position + 1);
return state;
}
main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int t; cin >> t;
FOR(int, _, 1, t){
cin >> n;
FOR(int, i, 1, n){
string ins; int v, k; cin >> ins >> v;
if (ins != "add") cin >> k;
instructions[i] = Instruction(ins, v, k);
}
FOR(int, i, 0, 255)
FOR(int, j, 0, n + 1) visited[i][j] = false;
bool answer = true;
State state = {0, 1}; visited[0][1] = true;
while (state.position < n + 1){
state = process(state, instructions[state.position]);
// cerr << state.value << '/' << state.position << ' ' <<visited[state.value][state.position] << '\n';
if (visited[state.value][state.position]){
answer = false;
break;
}
visited[state.value][state.position] = true;
}
cout << (answer ? "Yes\n" : "No\n");
}
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5916kb
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: 125ms
memory: 6520kb
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