제출 #521971

#제출 시각아이디문제언어결과실행 시간메모리
521971MonarchuwuDango Maker (JOI18_dango_maker)C++17
0 / 100
108 ms212084 KiB
#include<iostream> #include<algorithm> #include<vector> #include<queue> using namespace std; typedef long long ll; const int N = 3000 + 3, N2 = N * N, inf = 1e9 + 7; int m, n; char c[N][N]; vector<int> vertexX; int cnt, num[2][N][N]; vector<int> g[N2]; void init_graph() { for (int i = 0; i < m; ++i) for (int j = 0; j < n; ++j) if (c[i][j] == 'G') { bool flag11(false), flag12(false), flag21(false), flag22(false); // check ngang if (j > 0 && j + 1 < n && c[i][j - 1] == 'R' && c[i][j + 1] == 'W') { num[0][i][j] = ++cnt; if (i & 1) vertexX.push_back(num[0][i][j]); if (num[1][i - 1][j + 1]) { if (i & 1) g[num[0][i][j]].push_back(num[1][i - 1][j + 1]); else g[num[1][i - 1][j + 1]].push_back(num[0][i][j]); } } // check dọc if (i > 0 && i + 1 < m && c[i - 1][j] == 'R' && c[i + 1][j] == 'W') { num[1][i][j] = ++cnt; if (!(i & 1)) vertexX.push_back(num[1][i][j]); if (num[0][i - 1][j + 1]) { if (!(i & 1)) g[num[1][i][j]].push_back(num[0][i - 1][j + 1]); else g[num[0][i - 1][j + 1]].push_back(num[1][i][j]); } } if (num[0][i][j] && num[1][i][j]) { if (i & 1) g[num[0][i][j]].push_back(num[1][i][j]); else g[num[1][i][j]].push_back(num[0][i][j]); } } } int mat[N2]; int dist[N2]; bool bfs() { queue<int> q; dist[0] = inf; for (int i : vertexX) if (mat[i]) dist[i] = inf; else { dist[i] = 0; q.push(i); } while (!q.empty()) { int u = q.front(); q.pop(); for (int v : g[u]) { if (dist[mat[v]] == inf) { dist[mat[v]] = dist[u] + 1; q.push(mat[v]); } } } return dist[0] != inf; } bool dfs(int u) { for (int v : g[u]) { if (!mat[v] || (dist[mat[v]] == dist[u] + 1 && dfs(mat[v]))) { mat[v] = u, mat[u] = v; dist[u] = inf; return true; } } dist[u] = inf; return false; } int hopcroft_karp() { int ans(0); while (bfs()) { for (int i : vertexX) if (!mat[i] && dfs(i)) ++ans; } return ans; } int main() { cin.tie(NULL)->sync_with_stdio(false); cin >> m >> n; for (int i = 0; i < m; ++i) cin >> c[i]; init_graph(); cout << cnt - hopcroft_karp() << '\n'; } /** /\_/\ * (= ._.) * / >0 \>1 **/ /* ==================================================+ INPUT: | --------------------------------------------------| 4 4 xxxRx xxRGW xRGWx RGWxx --------------------------------------------------| ==================================================+ OUTPUT: | --------------------------------------------------| --------------------------------------------------| ==================================================+ */

컴파일 시 표준 에러 (stderr) 메시지

dango_maker.cpp: In function 'void init_graph()':
dango_maker.cpp:18:18: warning: unused variable 'flag11' [-Wunused-variable]
   18 |             bool flag11(false), flag12(false), flag21(false), flag22(false);
      |                  ^~~~~~
dango_maker.cpp:18:33: warning: unused variable 'flag12' [-Wunused-variable]
   18 |             bool flag11(false), flag12(false), flag21(false), flag22(false);
      |                                 ^~~~~~
dango_maker.cpp:18:48: warning: unused variable 'flag21' [-Wunused-variable]
   18 |             bool flag11(false), flag12(false), flag21(false), flag22(false);
      |                                                ^~~~~~
dango_maker.cpp:18:63: warning: unused variable 'flag22' [-Wunused-variable]
   18 |             bool flag11(false), flag12(false), flag21(false), flag22(false);
      |                                                               ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...