QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#646578 | #9224. Express Eviction | ucup-team2432 | WA | 283ms | 4160kb | C++17 | 2.8kb | 2024-10-17 01:33:34 | 2024-10-17 01:33:36 |
Judging History
answer
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define ll long long
#define all(v) v.begin(),v.end()
#define sz(v) ((ll)v.size())
#define V vector
#define vi V<int>
#define vll V<ll>
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define A array
#define pb push_back
#define mset multiset
#define gpumap __gnu_pbds::gp_hash_table
#define ccumap __gnu_pbds::cc_hash_table
#define ui unsigned int
#define ull unsigned ll
#define i128 __int128
#define cerr if (test) cerr
#define freopen if (test) freopen
#define whtest if (test)
using namespace std;
constexpr int test = 0;
namespace jhsy {
void main() {
int n,m;
cin >> n >> m;
n += 2; m += 2;
V a(n,vi(m));
for (int i = 1; i+1 < n; i++) {
string s;
cin >> s; s = '.'+s+'.';
for (int j = 0; j < m; j++) {
a[i][j] = s[j] == '#';
}
}
V id(n-1,vi(m-1));
int cnt = 0;
for (int i = 0; i < n-1; i++) {
for (int j = 0; j < m-1; j++) {
id[i][j] = cnt++;
}
}
auto build = [&](const auto &a) {
V<V<pii>> e(cnt);
for (int i = 0; i < n-1; i++) {
for (int j = 0; j+1 < m-1; j++) {
e[id[i][j]].eb(id[i][j+1],a[i][j+2]+a[i+1][j+2]);
e[id[i][j+1]].eb(id[i][j],a[i][j]+a[i+1][j]);
}
}
for (int i = 0; i+1 < n-1; i++) {
for (int j = 0; j < m-1; j++) {
e[id[i][j]].eb(id[i+1][j],a[i+2][j]+a[i+2][j+1]);
e[id[i+1][j]].eb(id[i][j],a[i][j]+a[i][j+1]);
}
}
return e;
};
auto Dij = [&](int s,int sd,const auto &e) {
constexpr int inf = 1e9;
V dis(cnt,inf);
priority_queue<pii,V<pii>,greater<>> q;
q.emplace(dis[s] = sd,s);
while (!q.empty()) {
auto [d,u] = q.top(); q.pop();
if (d == dis[u]) {
for (auto [v,w]:e[u]) {
if (dis[v] > d+w) {
q.emplace(dis[v] = d+w,v);
}
}
}
}
return dis;
};
auto e = build(a);
for (int x = 0; x < n-1; x++) {
for (int y = 0; y < m-1; y++) {
auto tmp = a;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
tmp[x+i][y+j] = 0;
}
}
auto dis = Dij(id[x][y],0,build(tmp));
for (auto [dx,dy]:V{pii{1,1},{1,-1},{-1,1},{-1,-1}}) {
int px = x+dx,py = y+dy;
auto legal = [&](int x,int y) {
return x >= 0 && x < n-1 && y >= 0 && y < m-1;
};
if (legal(px,py)) {
e[id[x][y]].eb(id[px][py],dis[id[px][py]]);
}
}
}
}
auto dis = Dij(id[0][0],a[1][1],e);
cout << dis[cnt-1] << '\n';
}
}
int main() {
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
// jhsy::init();
int T = 1;
// cin >> T;
while (T--) {
jhsy::main();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
4 6 .##... .#.... ##.... ....#.
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 61ms
memory: 3808kb
input:
20 30 ...########################### #..########################### ...########################### ...########################### .############################# ...########################### ...########################### #..########################### ...########################### ..#...............
output:
11
result:
ok 1 number(s): "11"
Test #3:
score: -100
Wrong Answer
time: 283ms
memory: 4160kb
input:
35 35 ....###########...#########........ ##..#######################..#####. ....#######################..#####. ...#.....##################..#####. .##......##################.....##. .##..##..#############.....#....##. .....##..#############......##..##. ....#....#############..##..##..##. ####.....
output:
21
result:
wrong answer 1st numbers differ - expected: '16', found: '21'