Please sign in first.
Submission #16752194
Source Code Expand
#include <iostream>
#include <atcoder/mincostflow>
using namespace std;
using namespace atcoder;
int main() {
int n, m;
cin >> n >> m;
vector<string> board(n);
for (int i = 0; i < n; i++) {
cin >> board[i];
}
mcf_graph<int, int> g(n * m + 2);
int sv = n * m, tv = sv + 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (board[i][j] == '#') continue;
g.add_edge(i * m + j, tv, 1, 10000 - i - j);
if (board[i][j] == 'o') {
g.add_edge(sv, i * m + j, 1, i + j);
}
if (i) {
g.add_edge((i - 1) * m + j, i * m + j, 10000, 0);
}
if (j) {
g.add_edge(i * m + (j - 1), i * m + j, 10000, 0);
}
}
}
auto answer = g.flow(sv, tv);
cout << answer.first * 10000 - answer.second << endl;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Moving Pieces |
| User | yosupo |
| Language | C++ (GCC 9.2.1 with AC Library) |
| Score | 600 |
| Code Size | 958 Byte |
| Status | AC |
| Exec Time | 31 ms |
| Memory | 4196 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 | 10 ms | 3568 KiB |
| 00-sample-02.txt | AC | 3 ms | 3520 KiB |
| 01-01.txt | AC | 2 ms | 3500 KiB |
| 01-02.txt | AC | 3 ms | 3576 KiB |
| 01-03.txt | AC | 3 ms | 3624 KiB |
| 01-04.txt | AC | 5 ms | 3816 KiB |
| 01-05.txt | AC | 8 ms | 4008 KiB |
| 01-06.txt | AC | 4 ms | 3636 KiB |
| 01-07.txt | AC | 20 ms | 4088 KiB |
| 01-08.txt | AC | 19 ms | 4080 KiB |
| 01-09.txt | AC | 18 ms | 4088 KiB |
| 01-10.txt | AC | 15 ms | 4036 KiB |
| 01-11.txt | AC | 15 ms | 4084 KiB |
| 01-12.txt | AC | 25 ms | 4196 KiB |
| 01-13.txt | AC | 31 ms | 4060 KiB |
| 01-14.txt | AC | 15 ms | 3896 KiB |
| 01-15.txt | AC | 8 ms | 3936 KiB |
| 01-16.txt | AC | 7 ms | 3928 KiB |
| 01-17.txt | AC | 16 ms | 4008 KiB |
| 01-18.txt | AC | 24 ms | 3780 KiB |
| 01-19.txt | AC | 18 ms | 3972 KiB |
| 01-20.txt | AC | 10 ms | 3892 KiB |
| 01-21.txt | AC | 9 ms | 3824 KiB |
| 01-22.txt | AC | 7 ms | 3880 KiB |
| 01-23.txt | AC | 15 ms | 3920 KiB |
| 01-24.txt | AC | 16 ms | 3884 KiB |
| 01-25.txt | AC | 7 ms | 3776 KiB |
| 01-26.txt | AC | 9 ms | 3852 KiB |
| 01-27.txt | AC | 7 ms | 3708 KiB |
| 01-28.txt | AC | 17 ms | 3864 KiB |
| 01-29.txt | AC | 10 ms | 3848 KiB |
| 01-30.txt | AC | 11 ms | 3892 KiB |
| 01-31.txt | AC | 11 ms | 3756 KiB |
| 01-32.txt | AC | 11 ms | 3860 KiB |
| 01-33.txt | AC | 12 ms | 3752 KiB |
| 01-34.txt | AC | 10 ms | 3852 KiB |
| 01-35.txt | AC | 7 ms | 3756 KiB |
| 01-36.txt | AC | 8 ms | 3836 KiB |
| 01-37.txt | AC | 9 ms | 3852 KiB |
| 01-38.txt | AC | 7 ms | 3872 KiB |
| 01-39.txt | AC | 6 ms | 3720 KiB |
| 01-40.txt | AC | 8 ms | 3812 KiB |
| 01-41.txt | AC | 6 ms | 3720 KiB |
| 01-42.txt | AC | 6 ms | 3768 KiB |