Submission #144972

#TimeUsernameProblemLanguageResultExecution timeMemory
144972SamAndTrapezi (COI17_trapezi)C++17
0 / 100
1077 ms376 KiB
#include <bits/stdc++.h> using namespace std; #define m_p make_pair const int N = 55; int n; char a[N][N]; int s[N]; vector<pair<int, int> > g[N][N]; int u[N][N]; bool c[N][N]; vector<pair<int, int> > v; int dfs(int x, int y) { v.push_back(m_p(x, y)); c[x][y] = true; for (int i = 0; i < g[x][y].size(); ++i) { pair<int, int> h = g[x][y][i]; if (!c[h.first][h.second] && u[x][y] == u[h.first][h.second]) dfs(h.first, h.second); } } int stg(int x, int y) { v.clear(); dfs(x, y); for (int i = 0; i < v.size(); ++i) c[v[i].first][v[i].second] = false; return v.size(); } void rec(int x, int y) { if (x == 2 * n + 1) { bool z = true; for (int i = 1; i <= 2 * n; ++i) { for (int j = ((4 * n - 1) - s[i]) / 2 + 1; j <= ((4 * n - 1) - s[i]) / 2 + s[i]; ++j) { if (a[i][j] == '0') { if (stg(i, j) != 3) z = false; break; } } if (!z) break; } if (z) { for (int i = 1; i <= 2 * n; ++i) { for (int j = ((4 * n - 1) - s[i]) / 2 + 1; j <= ((4 * n - 1) - s[i]) / 2 + s[i]; ++j) { cout << u[i][j]; } cout << endl; } exit(0); } return; } if (a[x][y] == '0') { for (int g = 1; g <= 6; ++g) { u[x][y] = g; if (stg(x, y) > 3) continue; if (y != ((4 * n - 1) - s[x]) / 2 + s[x]) { rec(x, y + 1); } else { rec(x + 1, ((4 * n - 1) - s[x + 1]) / 2 + 1); } } u[x][y] = 0; } else { if (y != ((4 * n - 1) - s[x]) / 2 + s[x]) { rec(x, y + 1); } else { rec(x + 1, ((4 * n - 1) - s[x + 1]) / 2 + 1); } } } int main() { //freopen("input.txt", "r", stdin); cin >> n; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) a[i][j] = '-'; } s[1] = 2 * n + 1; for (int i = 1; i <= 2 * n; ++i) { for (int j = ((4 * n - 1) - s[i]) / 2 + 1; j <= ((4 * n - 1) - s[i]) / 2 + s[i]; ++j) { cin >> a[i][j]; if (a[i][j] == a[i][j - 1]) { g[i][j].push_back(m_p(i, j - 1)); g[i][j - 1].push_back(m_p(i, j)); } if (i <= n && j % 2 == 0) { if (a[i][j] == '0' && a[i - 1][j] == '0') { g[i][j].push_back(m_p(i - 1, j)); g[i - 1][j].push_back(m_p(i, j)); } } if (i > n && j % 2 == 1) { if (a[i][j] == '0' && a[i - 1][j] == '0') { g[i][j].push_back(m_p(i - 1, j)); g[i - 1][j].push_back(m_p(i, j)); } } } if (i < n) { s[i + 1] = s[i] + 2; } else if (i == n) { s[i + 1] = s[i]; } else if (i > n) { s[i + 1] = s[i] - 2; } } /*cout << endl; for (int i = 1; i <= n * 2; ++i) { for (int j = 0; j < N; ++j) cout << a[i][j]; cout << endl; }*/ rec(1, ((4 * n - 1) - s[1]) / 2 + 1); cout << "nemoguce" << endl; return 0; }

Compilation message (stderr)

trapezi.cpp: In function 'int dfs(int, int)':
trapezi.cpp:20:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[x][y].size(); ++i)
                     ~~^~~~~~~~~~~~~~~~
trapezi.cpp:26:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
trapezi.cpp: In function 'int stg(int, int)':
trapezi.cpp:32:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...