Submission #16923883
Source Code Expand
#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; using namespace atcoder;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan0
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int H, W;
string S[50];
vector<pair<int,int>> circles;
int dist[101][50][50];
ll BASE = inf;
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> H >> W;
rep(y, 0, H) cin >> S[y];
int id = 0;
rep(y, 0, H) rep(x, 0, W) if (S[y][x] == 'o') {
circles.push_back({ x, y });
rep(xx, 0, W) rep(yy, 0, H) dist[id][yy][xx] = inf;
queue<tuple<int,int, int>> que;
dist[id][y][x] = 0;
que.push(make_tuple(x, y, 0));
while (!que.empty()) {
int x, y, cst;
tie(x, y, cst) = que.front(); que.pop();
if (x + 1 < W && S[y][x + 1] != '#' && dist[id][y][x + 1] == inf) {
dist[id][y][x + 1] = cst + 1;
que.push(make_tuple(x + 1, y, cst + 1));
}
if (y + 1 < H && S[y + 1][x] != '#' && dist[id][y + 1][x] == inf) {
dist[id][y + 1][x] = cst + 1;
que.push(make_tuple(x, y + 1, cst + 1));
}
}
id++;
}
mcf_graph<int, ll> g(H * W + id + 2);
int st = H * W + id;
int gl = st + 1;
rep(i, 0, id) {
g.add_edge(st, H * W + i, 1, 0);
rep(y, 0, H) rep(x, 0, W) if (dist[i][y][x] < inf) g.add_edge(H * W + i, y * W + x, 1, BASE - dist[i][y][x]);
}
rep(y, 0, H) rep(x, 0, W) if (S[y][x] != '#') g.add_edge(y * W + x, gl, 1, 0);
ll ans = -(g.flow(st, gl).second - BASE * id);
cout << ans << endl;
}
Submission Info
| Submission Time |
|
| Task |
C - Moving Pieces |
| User |
hamayanhamayan |
| Language |
C++ (GCC 9.2.1 with AC Library) |
| Score |
600 |
| Code Size |
2693 Byte |
| Status |
AC |
| Exec Time |
40 ms |
| Memory |
9836 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
600 / 600 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00-sample-01.txt, 00-sample-02.txt |
| All |
00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00-sample-01.txt |
AC |
6 ms |
3676 KiB |
| 00-sample-02.txt |
AC |
2 ms |
3680 KiB |
| 01-01.txt |
AC |
2 ms |
3512 KiB |
| 01-02.txt |
AC |
5 ms |
4324 KiB |
| 01-03.txt |
AC |
2 ms |
3752 KiB |
| 01-04.txt |
AC |
4 ms |
3696 KiB |
| 01-05.txt |
AC |
10 ms |
4800 KiB |
| 01-06.txt |
AC |
4 ms |
4136 KiB |
| 01-07.txt |
AC |
23 ms |
6828 KiB |
| 01-08.txt |
AC |
25 ms |
7004 KiB |
| 01-09.txt |
AC |
28 ms |
7032 KiB |
| 01-10.txt |
AC |
26 ms |
7264 KiB |
| 01-11.txt |
AC |
22 ms |
7012 KiB |
| 01-12.txt |
AC |
40 ms |
9836 KiB |
| 01-13.txt |
AC |
40 ms |
8648 KiB |
| 01-14.txt |
AC |
21 ms |
6036 KiB |
| 01-15.txt |
AC |
8 ms |
5024 KiB |
| 01-16.txt |
AC |
7 ms |
4944 KiB |
| 01-17.txt |
AC |
29 ms |
7740 KiB |
| 01-18.txt |
AC |
35 ms |
7084 KiB |
| 01-19.txt |
AC |
19 ms |
6328 KiB |
| 01-20.txt |
AC |
19 ms |
5844 KiB |
| 01-21.txt |
AC |
17 ms |
5500 KiB |
| 01-22.txt |
AC |
8 ms |
5336 KiB |
| 01-23.txt |
AC |
13 ms |
5260 KiB |
| 01-24.txt |
AC |
8 ms |
4988 KiB |
| 01-25.txt |
AC |
9 ms |
4940 KiB |
| 01-26.txt |
AC |
7 ms |
4840 KiB |
| 01-27.txt |
AC |
8 ms |
4952 KiB |
| 01-28.txt |
AC |
18 ms |
5468 KiB |
| 01-29.txt |
AC |
18 ms |
5400 KiB |
| 01-30.txt |
AC |
15 ms |
5328 KiB |
| 01-31.txt |
AC |
15 ms |
5520 KiB |
| 01-32.txt |
AC |
18 ms |
5576 KiB |
| 01-33.txt |
AC |
10 ms |
5128 KiB |
| 01-34.txt |
AC |
14 ms |
5136 KiB |
| 01-35.txt |
AC |
13 ms |
5088 KiB |
| 01-36.txt |
AC |
7 ms |
4996 KiB |
| 01-37.txt |
AC |
15 ms |
4936 KiB |
| 01-38.txt |
AC |
7 ms |
4888 KiB |
| 01-39.txt |
AC |
12 ms |
4948 KiB |
| 01-40.txt |
AC |
8 ms |
4848 KiB |
| 01-41.txt |
AC |
15 ms |
4876 KiB |
| 01-42.txt |
AC |
11 ms |
4840 KiB |