# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
220732 |
2020-04-08T13:41:30 Z |
NONAME |
Skandi (COCI20_skandi) |
C++17 |
|
4276 ms |
19064 KB |
#include <bits/stdc++.h>
#include <time.h>
//#include <random>
//#ifndef _LOCAL
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#endif
#define sz(x) int(x.size())
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#define N 100500
#define oo ll(1e16)
#define pii pair <int, int>
#define pll pair <ll, ll>
#define ft first
#define sd second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define el '\n'
#define elf endl
#define base ll(1e9 + 7)
#define re return
#define nins 4294967295
using namespace std;
typedef long long ll;
typedef long double ld;
//mt19937 rnd(0);
pii ver_co[501 * 501], hor_co[501 * 501];
int n, m, ver, hor;
vector <int> mV, mH, g[501 * 501], mkV, mkH;
vector <char> mk;
map <pii, int> ver_id, hor_id;
string s[501];
bool try_kuhn(int v) {
if (mk[v])
return 0;
mk[v] = 1;
for (int i = 0; i < sz(g[v]); i++) {
int to = g[v][i];
if (mH[to] == -1 || try_kuhn(mH[to])) {
mH[to] = v;
return 1;
}
}
return 0;
}
void dfs(int v) {
mkV[v] = 1;
for (int i = 0; i < sz(g[v]); i++) {
int to = g[v][i];
if (mkH[to])
continue;
mkH[to] = 1;
dfs(mH[to]);
}
}
void solve() {
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> s[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
if (s[i][j] == '0')
continue;
if (i + 1 < n && s[i + 1][j] == '0') {
ver_id[{i, j}] = ver;
ver_co[ver++] = {i + 1, j + 1};
}
if (j + 1 < m && s[i][j + 1] == '0') {
hor_id[{i, j}] = hor;
hor_co[hor++] = {i + 1, j + 1};
}
}
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
if (s[i][j] == '1')
continue;
int _i = i, _j = j;
while (s[_i][j] == '0') _i--;
while (s[i][_j] == '0') _j--;
g[ver_id[{_i, j}]].pb(hor_id[{i, _j}]);
}
int rs = 0;
mV.assign(ver, -1);
mH.assign(hor, -1);
for (int i = 0; i < ver; i++) {
mk.assign(ver, 0);
rs += try_kuhn(i);
}
cout << rs << el;
mkV.assign(ver, 0);
mkH.assign(hor, 0);
for (int i = 0; i < hor; i++)
if (mH[i] != -1)
mV[mH[i]] = i;
for (int i = 0; i < ver; i++) {
if (mV[i] != -1)
continue;
dfs(i);
}
for (int i = 0; i < ver; i++)
if (!mkV[i])
cout << ver_co[i].ft << ' ' << ver_co[i].sd << " DOLJE" << el;
for (int i = 0; i < hor; i++)
if (mkH[i])
cout << hor_co[i].ft << ' ' << hor_co[i].sd << " DESNO" << el;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef _LOCAL
in("input.txt");
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
cout << "Test #" << i << elf;
clock_t start_time = clock();
solve();
cerr.precision(4); cerr << fixed;
cerr << elf;
cerr << "Time :: " << ld(clock() - start_time) / CLOCKS_PER_SEC << elf;
cout << elf;
}
#else
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << el;
}
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
6272 KB |
Correct. |
2 |
Correct |
8 ms |
6272 KB |
Correct. |
3 |
Correct |
8 ms |
6272 KB |
Correct. |
4 |
Correct |
8 ms |
6272 KB |
Correct. |
5 |
Correct |
10 ms |
6272 KB |
Correct. |
6 |
Correct |
8 ms |
6272 KB |
Correct. |
7 |
Correct |
8 ms |
6272 KB |
Correct. |
8 |
Correct |
8 ms |
6272 KB |
Correct. |
9 |
Correct |
8 ms |
6272 KB |
Correct. |
10 |
Correct |
8 ms |
6272 KB |
Correct. |
11 |
Correct |
9 ms |
6272 KB |
Correct. |
12 |
Correct |
8 ms |
6272 KB |
Correct. |
13 |
Correct |
10 ms |
6272 KB |
Correct. |
14 |
Correct |
8 ms |
6272 KB |
Correct. |
15 |
Correct |
8 ms |
6272 KB |
Correct. |
16 |
Correct |
8 ms |
6272 KB |
Correct. |
17 |
Correct |
9 ms |
6196 KB |
Correct. |
18 |
Correct |
8 ms |
6272 KB |
Correct. |
19 |
Correct |
8 ms |
6272 KB |
Correct. |
20 |
Correct |
8 ms |
6272 KB |
Correct. |
21 |
Correct |
8 ms |
6272 KB |
Correct. |
22 |
Correct |
8 ms |
6272 KB |
Correct. |
23 |
Correct |
11 ms |
6272 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
6272 KB |
Correct. |
2 |
Correct |
8 ms |
6272 KB |
Correct. |
3 |
Correct |
9 ms |
6400 KB |
Correct. |
4 |
Correct |
8 ms |
6272 KB |
Correct. |
5 |
Correct |
9 ms |
6272 KB |
Correct. |
6 |
Correct |
9 ms |
6272 KB |
Correct. |
7 |
Correct |
8 ms |
6272 KB |
Correct. |
8 |
Correct |
10 ms |
6400 KB |
Correct. |
9 |
Correct |
9 ms |
6400 KB |
Correct. |
10 |
Correct |
9 ms |
6528 KB |
Correct. |
11 |
Correct |
12 ms |
6528 KB |
Correct. |
12 |
Correct |
12 ms |
6528 KB |
Correct. |
13 |
Correct |
9 ms |
6528 KB |
Correct. |
14 |
Correct |
10 ms |
6528 KB |
Correct. |
15 |
Correct |
9 ms |
6528 KB |
Correct. |
16 |
Correct |
10 ms |
6528 KB |
Correct. |
17 |
Correct |
9 ms |
6528 KB |
Correct. |
18 |
Correct |
12 ms |
6400 KB |
Correct. |
19 |
Correct |
9 ms |
6528 KB |
Correct. |
20 |
Correct |
10 ms |
6400 KB |
Correct. |
21 |
Correct |
9 ms |
6528 KB |
Correct. |
22 |
Correct |
10 ms |
6528 KB |
Correct. |
23 |
Correct |
11 ms |
6528 KB |
Correct. |
24 |
Correct |
9 ms |
6400 KB |
Correct. |
25 |
Correct |
13 ms |
6504 KB |
Correct. |
26 |
Correct |
9 ms |
6528 KB |
Correct. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
6272 KB |
Correct. |
2 |
Correct |
8 ms |
6272 KB |
Correct. |
3 |
Correct |
8 ms |
6272 KB |
Correct. |
4 |
Correct |
8 ms |
6272 KB |
Correct. |
5 |
Correct |
10 ms |
6272 KB |
Correct. |
6 |
Correct |
8 ms |
6272 KB |
Correct. |
7 |
Correct |
8 ms |
6272 KB |
Correct. |
8 |
Correct |
8 ms |
6272 KB |
Correct. |
9 |
Correct |
8 ms |
6272 KB |
Correct. |
10 |
Correct |
8 ms |
6272 KB |
Correct. |
11 |
Correct |
9 ms |
6272 KB |
Correct. |
12 |
Correct |
8 ms |
6272 KB |
Correct. |
13 |
Correct |
10 ms |
6272 KB |
Correct. |
14 |
Correct |
8 ms |
6272 KB |
Correct. |
15 |
Correct |
8 ms |
6272 KB |
Correct. |
16 |
Correct |
8 ms |
6272 KB |
Correct. |
17 |
Correct |
9 ms |
6196 KB |
Correct. |
18 |
Correct |
8 ms |
6272 KB |
Correct. |
19 |
Correct |
8 ms |
6272 KB |
Correct. |
20 |
Correct |
8 ms |
6272 KB |
Correct. |
21 |
Correct |
8 ms |
6272 KB |
Correct. |
22 |
Correct |
8 ms |
6272 KB |
Correct. |
23 |
Correct |
11 ms |
6272 KB |
Correct. |
24 |
Correct |
8 ms |
6272 KB |
Correct. |
25 |
Correct |
8 ms |
6272 KB |
Correct. |
26 |
Correct |
9 ms |
6400 KB |
Correct. |
27 |
Correct |
8 ms |
6272 KB |
Correct. |
28 |
Correct |
9 ms |
6272 KB |
Correct. |
29 |
Correct |
9 ms |
6272 KB |
Correct. |
30 |
Correct |
8 ms |
6272 KB |
Correct. |
31 |
Correct |
10 ms |
6400 KB |
Correct. |
32 |
Correct |
9 ms |
6400 KB |
Correct. |
33 |
Correct |
9 ms |
6528 KB |
Correct. |
34 |
Correct |
12 ms |
6528 KB |
Correct. |
35 |
Correct |
12 ms |
6528 KB |
Correct. |
36 |
Correct |
9 ms |
6528 KB |
Correct. |
37 |
Correct |
10 ms |
6528 KB |
Correct. |
38 |
Correct |
9 ms |
6528 KB |
Correct. |
39 |
Correct |
10 ms |
6528 KB |
Correct. |
40 |
Correct |
9 ms |
6528 KB |
Correct. |
41 |
Correct |
12 ms |
6400 KB |
Correct. |
42 |
Correct |
9 ms |
6528 KB |
Correct. |
43 |
Correct |
10 ms |
6400 KB |
Correct. |
44 |
Correct |
9 ms |
6528 KB |
Correct. |
45 |
Correct |
10 ms |
6528 KB |
Correct. |
46 |
Correct |
11 ms |
6528 KB |
Correct. |
47 |
Correct |
9 ms |
6400 KB |
Correct. |
48 |
Correct |
13 ms |
6504 KB |
Correct. |
49 |
Correct |
9 ms |
6528 KB |
Correct. |
50 |
Correct |
150 ms |
16892 KB |
Correct. |
51 |
Correct |
4276 ms |
10600 KB |
Correct. |
52 |
Correct |
180 ms |
17400 KB |
Correct. |
53 |
Correct |
172 ms |
16888 KB |
Correct. |
54 |
Correct |
146 ms |
15740 KB |
Correct. |
55 |
Correct |
192 ms |
18388 KB |
Correct. |
56 |
Correct |
164 ms |
17656 KB |
Correct. |
57 |
Correct |
167 ms |
17400 KB |
Correct. |
58 |
Correct |
2742 ms |
9924 KB |
Correct. |
59 |
Correct |
141 ms |
16052 KB |
Correct. |
60 |
Correct |
162 ms |
17528 KB |
Correct. |
61 |
Correct |
149 ms |
14456 KB |
Correct. |
62 |
Correct |
176 ms |
17656 KB |
Correct. |
63 |
Correct |
164 ms |
17784 KB |
Correct. |
64 |
Correct |
198 ms |
7672 KB |
Correct. |
65 |
Correct |
163 ms |
17656 KB |
Correct. |
66 |
Correct |
147 ms |
15736 KB |
Correct. |
67 |
Correct |
177 ms |
15864 KB |
Correct. |
68 |
Correct |
192 ms |
18296 KB |
Correct. |
69 |
Correct |
164 ms |
17120 KB |
Correct. |
70 |
Correct |
159 ms |
17272 KB |
Correct. |
71 |
Correct |
190 ms |
17912 KB |
Correct. |
72 |
Correct |
170 ms |
18428 KB |
Correct. |
73 |
Correct |
194 ms |
18680 KB |
Correct. |
74 |
Correct |
193 ms |
17660 KB |
Correct. |
75 |
Correct |
197 ms |
19064 KB |
Correct. |