QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#770913 | #9551. The Emperor | ucup-team3646 | WA | 4ms | 17440kb | C++20 | 2.8kb | 2024-11-22 01:52:21 | 2024-11-22 01:52:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, l, r) for (ll i = l; i < r; i++)
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
#define all(A) A.begin(), A.end()
#define elif else if
using pii = pair<ll, ll>;
bool chmin(auto &a, const auto &b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, const auto &b) { return a < b ? a = b, 1 : 0; }
struct IOSetup
{
IOSetup()
{
cin.tie(0);
ios::sync_with_stdio(0);
}
} iosetup;
template <class T>
void print(vector<T> a)
{
for (auto x : a)
cerr << x << ' ';
cout << endl;
}
void print(auto x) { cout << x << endl; }
template <class Head, class... Tail>
void print(Head &&head, Tail &&...tail)
{
cout << head << ' ';
print(forward<Tail>(tail)...);
}
const ll mod = 998244353;
int N;
vector<pair<int, int>> POP, PUSH;
vector<array<ll, 3>> todo1;
vi todo2;
vvi seen(1100, vi(1100, 0));
vi TO(1100, -1), NOW(1100, -1);
vector<vll> dist(1100, vll(1100, -1));
void add(int frm, int to, ll w)
{
if (frm == 0 && POP[to].first == -1)
{
cout << (w + 1) % mod << endl;
exit(0);
}
if (dist[frm][to] != -1)
return;
if (TO[frm] == -1)
{
TO[frm] = to;
NOW[frm] = to;
}
dist[frm][to] = w;
todo1.push_back({frm,to,w});
todo2.push_back(frm);
}
void search(int v)
{
int nxt = TO[NOW[v]];
if (nxt != -1)
{
ll w = dist[v][NOW[v]] + dist[NOW[v]][nxt];
w %= mod;
todo1.push_back({v, nxt, w});
NOW[v] = nxt;
}
}
int main()
{
cin >> N;
POP.resize(N);
PUSH.resize(N);
rep(i, N)
{
string s;
cin >> s;
if (s[0] == 'P')
{
cin >> POP[i].first;
cin >> s;
cin >> POP[i].second;
cin >> s;
POP[i].second--;
}
else
{
POP[i] = {-1, -1};
}
cin >> s;
cin >> PUSH[i].first;
cin >> s;
cin >> PUSH[i].second;
PUSH[i].second--;
}
if (POP[0].first == -1)
{
cout << 1 << endl;
exit(0);
}
vvi G(N);
rep(v, N)
{
G[PUSH[v].second].push_back(v);
}
rep(v, N)
{
if (POP[v].first != -1)
{
int to = POP[v].second;
for (auto frm : G[v])
{
if (PUSH[frm].first == POP[v].first)
{
add(frm, to, 2);
}
}
}
}
while (todo1.size() > 0 || todo2.size() > 0)
{
if (todo1.size() > 0)
{
auto [frm, to, w] = todo1.back();
todo1.pop_back();
for (auto frm2 : G[frm])
{
if (PUSH[frm2].first == POP[to].first)
{
add(frm2, POP[to].second, (w + 2) % mod);
}
}
}
else
{
int v = todo2.back();
todo2.pop_back();
search(v);
}
}
cout << -1 << endl;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 17200kb
input:
1 HALT; PUSH 1 GOTO 1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 17440kb
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: 0ms
memory: 17344kb
input:
1 POP 1 GOTO 1; PUSH 1 GOTO 1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 17356kb
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:
150994941
result:
ok 1 number(s): "150994941"
Test #5:
score: -100
Wrong Answer
time: 4ms
memory: 17192kb
input:
60 POP 1 GOTO 2; PUSH 1 GOTO 1 POP 51 GOTO 3; PUSH 51 GOTO 2 POP 2 GOTO 4; PUSH 2 GOTO 1 POP 52 GOTO 5; PUSH 52 GOTO 4 POP 3 GOTO 6; PUSH 3 GOTO 1 POP 53 GOTO 7; PUSH 53 GOTO 6 POP 4 GOTO 8; PUSH 4 GOTO 1 POP 54 GOTO 9; PUSH 54 GOTO 8 POP 5 GOTO 10; PUSH 5 GOTO 1 POP 55 GOTO 11; PUSH 55 GOTO 10 POP ...
output:
-1
result:
wrong answer 1st numbers differ - expected: '150994941', found: '-1'