QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#386233 | #7779. Swiss Stage | iwew# | AC ✓ | 1ms | 3832kb | C++20 | 1.3kb | 2024-04-11 14:20:43 | 2024-04-11 14:20:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
int dp[N], din[N];
int cost[N][N];
vector<pair<int, int>> adj[N];
void init() {
int ed = 23;
cost[0][0] = cost[0][1] = cost[1][0] = cost[1][1] = 1;
cost[1][2] = cost[2][1] = cost[2][2] = cost[2][0] = cost[0][2] = 2;
for(int i = 0; i <= 2; i ++ ) {
for(int j = 0; j <= 2; j ++ ) {
if(i + 1 == 3) {
adj[ed].push_back({i * 10 + j, cost[i][j]});
din[i * 10 + j] ++ ;
} else {
adj[(i + 1) * 10 + j].push_back({i * 10 + j, cost[i][j]});
din[i * 10 + j] ++ ;
}
if(j + 1 < 3) {
adj[i * 10 + j + 1].push_back({i * 10 + j, 1});
din[i * 10 + j] ++ ;
}
}
}
for(int i = 0; i < N; i ++ ) dp[i] = 1e9;
queue<int> que;
que.push(ed);
dp[ed] = 0;
while(que.size()) {
auto t = que.front();
que.pop();
for(auto [v, w] : adj[t]) {
din[v] -- ;
dp[v] = min(dp[v], dp[t] + w);
if(din[v] == 0) que.push(v);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
init();
int n, m;
cin >> n >> m;
cout << dp[n * 10 + m] << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3832kb
input:
0 1
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
1 2
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
0 0
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
0 2
output:
6
result:
ok 1 number(s): "6"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
1 0
output:
3
result:
ok 1 number(s): "3"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
1 1
output:
3
result:
ok 1 number(s): "3"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
2 0
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
2 1
output:
2
result:
ok 1 number(s): "2"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
2 2
output:
2
result:
ok 1 number(s): "2"
Extra Test:
score: 0
Extra Test Passed