QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#673444 | #9224. Express Eviction | ucup-team191# | WA | 0ms | 4500kb | C++23 | 2.5kb | 2024-10-24 22:25:28 | 2024-10-24 22:25:29 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
#define PB push_back
#define sz(x) ((int)(x).size())
using namespace std;
typedef pair < int, int > pii;
typedef vector < int > vi;
const int N = 54;
const int M = 1e5 + 500;
int A[N][N];
/**
const ll INF = (1LL << 60);
struct Dinic {
struct Edge {
int to, rev;
ll c, oc;
ll flow() { return max(oc - c, 0LL); }
};
vi lvl, ptr, q;
vector<vector<Edge>> adj;
Dinic(int n) : lvl(n), ptr(n), q(n), adj(n) {}
void addEdge(int a, int b, ll c, ll rcap = 0) {
adj[a].push_back({b, sz(adj[b]), c, c});
adj[b].push_back({a, sz(adj[a]) - 1, rcap, rcap});
}
ll dfs(int v, int t, ll f) {
if(v == t || !f) return f;
for(int &i = ptr[v]; i < sz(adj[v]);i++) {
Edge& e = adj[v][i];
if (lvl[e.to] == lvl[v] + 1) {
if(ll p = dfs(e.to, t, min(f, e.c))) {
e.c -= p, adj[e.to][e.rev].c += p;
return p;
}
}
}
return 0;
}
ll calc(int s, int t) {
ll flow = 0; q[0] = s;
for(int L = 0;L < 31;L++) do {
lvl = ptr = vi(sz(q));
int qi = 0, qe = lvl[s] = 1;
while(qi < qe && !lvl[t]) {
int v = q[qi++];
for (Edge e : adj[v]) {
if(!lvl[e.to] && e.c >> (30 - L)) {
q[qe++] = e.to, lvl[e.to] = lvl[v] + 1;
}
}
while (ll p = dfs(s, t, INF)) flow += p;
}
} while(lvl[t]);
return flow;
}
};
**/
int n, m;
char s[N][N];
vector < pii > v[M];
int dis[M];
int get(int A, int B) {
if(A < 0 || A >= n) return 0;
if(B < 0 || B >= m) return 0;
return s[A][B] == '#';
}
int code(int A, int B) {
return A * (m + 1) + B;
}
int main() {
scanf("%d%d", &n, &m);
for(int i = 0;i < n;i++) scanf("%s", s[i]);
for(int i = 0;i <= n;i++) {
for(int j = 0;j <= m;j++) {
if(i + 1 <= n) {
v[code(i, j)].PB({code(i + 1, j), get(i + 1, j - 1) + get(i + 1, j)});
v[code(i + 1, j)].PB({code(i, j), get(i - 1, j - 1) + get(i - 1, j)});
}
if(j + 1 <= m) {
v[code(i, j)].PB({code(i, j + 1), get(i - 1, j + 1) + get(i, j + 1)});
v[code(i, j + 1)].PB({code(i, j), get(i - 1, j - 1) + get(i, j - 1)});
}
}
}
memset(dis, -1, sizeof(dis));
dis[0] = get(0, 0);
set < pii > S;
S.insert({0, 0});
for(;!S.empty();) {
int cur = S.begin()->second;
S.erase(S.begin());
for(auto &[nxt, weight] : v[cur]) {
if(dis[nxt] == -1 || weight + dis[cur] < dis[nxt]) {
dis[nxt] = dis[cur] + weight;
S.insert({dis[nxt], nxt});
}
}
}
printf("%d\n", dis[code(n, m)]);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4456kb
input:
4 6 .##... .#.... ##.... ....#.
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 4500kb
input:
20 30 ...########################### #..########################### ...########################### ...########################### .############################# ...########################### ...########################### #..########################### ...########################### ..#...............
output:
12
result:
wrong answer 1st numbers differ - expected: '11', found: '12'