Submission #1519531
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define maxn 202 #define FOR(i, l, r) for (int i=l; i<=r; ++i) #define FORD(i, r, l) for (int i=r; i>=l; --i) #define REP(i, r) for (int i=0; i<(int)r; ++i) #define REPD(i, r) for (int i=(int)r-1; i>=0; --i) #define fi first #define se second #define mk make_pair #define nil NULL #define y0 __y0 #define y1 __y1 #define x0 __x0 #define x1 __x1 #define next __next #define sz size #define Debug(X) {cerr << #X << " = " << X << '\n';} #define PR(A, n) {cerr << #A << " = "; FOR(i, 1, n) cerr << A[i] << ' '; cerr << '\n';} #define PR0(A, n) {cerr << #A << " = "; REP(i, n) cerr << A[i] << ' '; cerr << '\n';} typedef long long ll; typedef double db; typedef pair<db, db> dd; typedef pair<int, int> ii; typedef vector<int> vi; const int inf = 1e9; template<class T> int getbit(T x, int pos) {return (x>>(pos-1)) & 1;} template<class T> void turn_on(T &x, int pos) {x = x | ((T)1<<(pos-1));} template<class T> void turn_off(T &x, int pos) {x = x & ~((T)1<<(pos-1));} template<class T> T sqr(T a) {return a*a;} int m, n, d[maxn], f[maxn][maxn], c[maxn][maxn], s, t; char lake[maxn][maxn]; vector<int> a[maxn]; queue<int> qu; bool findPath(int s, int t) { while (qu.sz()) qu.pop(); qu.push(s); memset(d, 0, sizeof(d)); while (qu.sz()) { int u = qu.front(); qu.pop(); if (u==t) return true; REP(i, a[u].sz()) { int v = a[u][i]; if (d[v]==0 && c[u][v]>f[u][v]) { d[v] = u; qu.push(v); } } } return false; } void incFlow() { int delta = inf; for (int v = t; v!=s; v = d[v]) delta = min(delta, c[d[v]][v] - f[d[v]][v]); for (int v = t; v!=s; v = d[v]) { f[d[v]][v] += delta; f[v][d[v]] -= delta; } } int main() { //freopen("lotus.inp", "r", stdin); //freopen(".out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cin >> m >> n; FOR(i, 1, m) FOR(j, 1, n) cin >> lake[i][j]; FOR(i, 1, m) FOR(j, 1, n) { if (lake[i][j]!='.') { a[i].push_back(m+j); a[m+j].push_back(i); if (lake[i][j]=='o') c[i][m+j] = c[m+j][i] = 1; else c[i][m+j] = c[m+j][i] = inf; } if (lake[i][j]=='S') s = i; if (lake[i][j]=='T') t = m+j; } while (findPath(s, t)) incFlow(); int res = 0; REP(i, a[s].sz()) { res += f[s][a[s][i]]; } if (res>=inf) printf("-1"); else printf("%d", res); }
Submission Info
Submission Time | |
---|---|
Task | F - Lotus Leaves |
User | phong22kk11 |
Language | C++14 (GCC 5.4.1) |
Score | 800 |
Code Size | 2623 Byte |
Status | AC |
Exec Time | 7 ms |
Memory | 768 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 800 / 800 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 1 ms | 256 KB |
0_01.txt | AC | 1 ms | 256 KB |
0_02.txt | AC | 1 ms | 256 KB |
0_03.txt | AC | 1 ms | 256 KB |
1_00.txt | AC | 1 ms | 256 KB |
1_01.txt | AC | 1 ms | 256 KB |
1_02.txt | AC | 1 ms | 256 KB |
1_03.txt | AC | 1 ms | 256 KB |
1_04.txt | AC | 1 ms | 384 KB |
1_05.txt | AC | 1 ms | 512 KB |
1_06.txt | AC | 7 ms | 768 KB |
1_07.txt | AC | 1 ms | 384 KB |
1_08.txt | AC | 2 ms | 640 KB |
1_09.txt | AC | 4 ms | 640 KB |
1_10.txt | AC | 1 ms | 512 KB |
1_11.txt | AC | 2 ms | 640 KB |
1_12.txt | AC | 1 ms | 512 KB |
1_13.txt | AC | 2 ms | 640 KB |
1_14.txt | AC | 2 ms | 640 KB |
1_15.txt | AC | 1 ms | 512 KB |
1_16.txt | AC | 2 ms | 512 KB |
1_17.txt | AC | 1 ms | 512 KB |
1_18.txt | AC | 2 ms | 640 KB |
1_19.txt | AC | 2 ms | 640 KB |
1_20.txt | AC | 1 ms | 512 KB |
1_21.txt | AC | 2 ms | 512 KB |
1_22.txt | AC | 1 ms | 512 KB |
1_23.txt | AC | 2 ms | 640 KB |
1_24.txt | AC | 1 ms | 512 KB |
1_25.txt | AC | 1 ms | 512 KB |
1_26.txt | AC | 1 ms | 512 KB |
1_27.txt | AC | 2 ms | 640 KB |
1_28.txt | AC | 2 ms | 512 KB |
1_29.txt | AC | 2 ms | 640 KB |
1_30.txt | AC | 1 ms | 512 KB |
1_31.txt | AC | 2 ms | 640 KB |
1_32.txt | AC | 3 ms | 640 KB |
1_33.txt | AC | 1 ms | 512 KB |
1_34.txt | AC | 2 ms | 512 KB |
1_35.txt | AC | 2 ms | 640 KB |
1_36.txt | AC | 2 ms | 512 KB |
1_37.txt | AC | 2 ms | 640 KB |
1_38.txt | AC | 1 ms | 512 KB |
1_39.txt | AC | 3 ms | 640 KB |
1_40.txt | AC | 1 ms | 512 KB |
1_41.txt | AC | 2 ms | 640 KB |
1_42.txt | AC | 1 ms | 512 KB |
1_43.txt | AC | 1 ms | 512 KB |
1_44.txt | AC | 1 ms | 384 KB |
1_45.txt | AC | 1 ms | 512 KB |
1_46.txt | AC | 1 ms | 512 KB |
1_47.txt | AC | 1 ms | 512 KB |
1_48.txt | AC | 1 ms | 512 KB |
1_49.txt | AC | 2 ms | 640 KB |