QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#760456 | #9551. The Emperor | AzusidNya | WA | 4ms | 23372kb | C++17 | 2.3kb | 2024-11-18 17:01:13 | 2024-11-18 17:01:14 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define eb emplace_back
#define mp make_pair
#define DEBUG
using namespace std;
using pii = pair<int, int>;
using piii = pair<int, pii>;
using piiii = pair<pii, pii>;
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned int;
const int P = 998244353;const i64 inf = 0x3f3f3f3f3f3f3f3f;
namespace IO{
#define AzusIO
int read(int &x){
x = 0; int ch = 1;
char u;
while(!(isdigit(u = getchar()))){ if(u == '-') ch = -1; }
x = u - '0';
while(isdigit(u = getchar())) {x = (x << 3) + (x << 1) + u - '0';}
x *= ch; return 0;
}
} using namespace IO;
namespace azus{
int n;
pii f[1105][1105];
bool vis[1105][1105];
int opt[1105];
int pu[1105], po[1105], tp[1105], tp2[1105];
pii dfs(int u, int a){
// cout << u << " " << a << "\n";
if(a == 0 && opt[u] == 0) return f[u][a] = mp(1ll, 0ll);
if(a == po[u]){
return f[u][a] = mp(1ll, tp[u]);
}
if(vis[u][a]) {
puts("-1");
exit(0); return mp(-1ll, -1ll);
}
if(f[u][a] != mp(-1ll, -1ll)) return f[u][a];
vis[u][a] = 1;
int y = tp2[u], b = pu[u];
auto [cnt1, z1] = dfs(y, b);
if(z1 == 0) f[u][a] = mp(cnt1 + 1, z1);
else {
auto [cnt2, z2] = dfs(z1, a);
f[u][a] = mp(cnt1 + cnt2 + 1, z2);
}
vis[u][a] = 0;
return f[u][a];
}
int main(){
for(int i = 0; i <= 1100; i ++)
for(int j = 0; j <= 1100; j ++) f[i][j] = mp(-1ll, -1ll);
read(n);
for(int i = 1; i <= n; i ++){
char ch = getchar();
if(ch == 'H'){
opt[i] = 0;
read(pu[i]); read(tp2[i]);
} else {
opt[i] = 1;
read(po[i]); read(tp[i]); read(pu[i]); read(tp2[i]);
}
// cout << opt[i] << "\n";
}
dfs(1, 0);
// cout << f[1][0].second << "\n";
assert(f[1][0].second == 0);
cout << f[1][0].first << "\n";
return 0;
}
}
signed main(){
#ifndef DEBUG
// ios::sync_with_stdio(0);
// cin.tie(0), cout.tie(0);
#endif
int T = 1;
while(T --)
azus::main();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 23352kb
input:
1 HALT; PUSH 1 GOTO 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 2ms
memory: 22692kb
input:
5 POP 1 GOTO 2; PUSH 1 GOTO 2 HALT; PUSH 1 GOTO 3 POP 1 GOTO 4; PUSH 2 GOTO 4 POP 1 GOTO 2; PUSH 2 GOTO 4 HALT; PUSH 99 GOTO 4
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 4ms
memory: 22676kb
input:
1 POP 1 GOTO 1; PUSH 1 GOTO 1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: -100
Wrong Answer
time: 4ms
memory: 23372kb
input:
61 POP 62 GOTO 61; PUSH 30 GOTO 60 POP 1 GOTO 3; PUSH 62 GOTO 61 POP 2 GOTO 61; PUSH 62 GOTO 61 POP 4 GOTO 7; PUSH 2 GOTO 61 POP 62 GOTO 61; PUSH 3 GOTO 4 POP 62 GOTO 61; PUSH 3 GOTO 5 POP 5 GOTO 10; PUSH 3 GOTO 6 POP 62 GOTO 61; PUSH 4 GOTO 7 POP 62 GOTO 61; PUSH 4 GOTO 8 POP 6 GOTO 12; PUSH 4 GOTO...
output:
2147483647
result:
wrong answer 1st numbers differ - expected: '150994941', found: '2147483647'