QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#724573 | #5202. Dominoes | cyj888 | AC ✓ | 19ms | 19332kb | C++14 | 1.8kb | 2024-11-08 13:50:01 | 2024-11-08 13:50:04 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define ott(i,l,r) for (int i = l; i <= r; i ++)
#define tto(i,l,r) for (int i = r; i >= l; i --)
using namespace std;
int read () {
int x = 0; bool f = false; char c = getchar ();
while (!isdigit (c)) f |= (c == '-'), c = getchar ();
while (isdigit (c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar ();
return f ? -x : x;
}
typedef long long ll;
const int N = 2200;
int n, m, c, bc, wc, tot, cnt;
ll res; int id[N][N], dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
bool vis[N], ok[N][N]; char s[N]; int bl[N];
vector <pair <int, int> > b, w;
vector <int> e[N];
bool match (int u) {
for (int v : e[u]) {
if (vis[v]) continue; vis[v] = true;
if (!bl[v] || match (bl[v])) return bl[v] = u, true;
}
return false;
}
void dfs (int z, int u) {
for (int v : e[u]) {
if (vis[v]) continue; vis[v] = true;
ok[z][v] = true; dfs (z, bl[v]);
}
return ;
}
int main () {
n = read (), m = read ();
ott (i, 1, n) {
scanf ("%s", s + 1);
ott (j, 1, m) {
if (s[j] ^ '.') continue;
if (i + j & 1) b.pb ({i, j}), id[i][j] = ++ bc;
else w.pb ({i, j}), id[i][j] = ++ wc;
}
}
res = 1ll * bc * (bc - 1) / 2ll + 1ll * wc * (wc - 1) / 2ll;
if (res >= 1e6) return puts ("1000000"), 0;
// printf ("%lld\n", res);
for (auto [x, y] : b) {
int u = id[x][y];
ott (i, 0, 3) {
int v = id[x + dx[i]][y + dy[i]];
if (v) e[u].pb (v);
}
}
for (auto [x, y] : b) {
fill (vis + 1, vis + 1 + wc, false);
if (match (id[x][y])) ++ c;
}
assert (c == bc);
for (auto [x, y] : b) {
fill (vis + 1, vis + 1 + wc, false);
dfs (id[x][y], id[x][y]);
}
ott (u, 1, bc)
ott (v, 1, wc)
if (!ok[u][v])
++ res;
if (res >= 1e6) res = 1e6;
printf ("%lld\n", res);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 6004kb
input:
3 6 ...#.. ...... #...##
output:
52
result:
ok 1 number(s): "52"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5920kb
input:
2 2 .. ..
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 0ms
memory: 5988kb
input:
2 2 #. #.
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 0ms
memory: 5984kb
input:
4 5 ###.. .###. .##.. #...#
output:
34
result:
ok 1 number(s): "34"
Test #5:
score: 0
Accepted
time: 0ms
memory: 6032kb
input:
11 12 .#######..## .##..#.....# #####..##.#. #..##...#... ###..#..##.. ####..###... .#....##..## .#####....## .###..###### .######...## #....##...##
output:
1674
result:
ok 1 number(s): "1674"
Test #6:
score: 0
Accepted
time: 2ms
memory: 7008kb
input:
50 45 ####...#.#####..#..#.#########.##.#####..#..# ##.#.....#..#####....##..###...##.....##....# ##.#...####.##.#..#...####.#....##.###....... ...#...#..#..#.##.######...##..#...###..####. ##.....#.###.####.###..#....##..##..##.###... ..#.##.......##...##.........#..##.###.###... ###..##.###...###....
output:
496312
result:
ok 1 number(s): "496312"
Test #7:
score: 0
Accepted
time: 0ms
memory: 8508kb
input:
34 65 ...............#####.#..##..############.....###....#..########## .........#......#.......##..############.##..##........########## ..............#.......#.....##########..............##.########## ...##............#..............######.......#......#..########## ......#....#.....##......#.......
output:
279744
result:
ok 1 number(s): "279744"
Test #8:
score: 0
Accepted
time: 19ms
memory: 9556kb
input:
44 44 ............................................ ............................................ ............................................ ............................................ ............................................ ............................................ ...........................
output:
936056
result:
ok 1 number(s): "936056"
Test #9:
score: 0
Accepted
time: 17ms
memory: 8460kb
input:
45 45 ............................................. ............................................. ............................................. ............................................. ............................................. ............................................. .....................
output:
999000
result:
ok 1 number(s): "999000"
Test #10:
score: 0
Accepted
time: 15ms
memory: 11304kb
input:
59 59 ...#.......#.......#...#...#...................#........... .#.#.#####.#.#####.#.#.#.#.#.#################.#.#########. .#.#.#.....#.#...#.#.#.#.#.#.#...............#.#.#...#...#. .#.#.#.#####.#.#.#.#.#.#.#.#.#.#############.#.#.#.#.#.#.#. .#.#.#.#...#.#.#.#...#...#...#.#...#.........#...#.#.#...
output:
809100
result:
ok 1 number(s): "809100"
Test #11:
score: 0
Accepted
time: 18ms
memory: 11052kb
input:
39 99 ...#.......#...#...................#...#...#...#...#...........#...#.......#....................... .#.#.#####.#.#.#.#################.#.#.#.#.#.#.#.#.#.#########.#.#.#.#####.#.#####################. .#.#.....#.#.#.#.........#.........#.#.#.#.#.#.#.#.#.#...#.....#.#.#.#.....#.....#.......#...#...
output:
999000
result:
ok 1 number(s): "999000"
Test #12:
score: 0
Accepted
time: 14ms
memory: 9696kb
input:
99 39 .......#.......#....................... .#####.#.#####.#.#####################. .....#.#.....#.#.#.......#............. ####.#.#####.#.#.#.#####.#.############ .....#.#.....#...#.#.....#.#........... .#####.#.#########.#.#####.#.#########. .....#.#.....#...#.#.....#.#.....#..... ####.#.#####.#...
output:
999000
result:
ok 1 number(s): "999000"
Test #13:
score: 0
Accepted
time: 14ms
memory: 9712kb
input:
45 45 #.......................................###.. .........................................##.. ............................................. ............................................. ............................................. ............................................. .....................
output:
999000
result:
ok 1 number(s): "999000"
Test #14:
score: 0
Accepted
time: 3ms
memory: 11004kb
input:
132 453 ###########################################################..####################..###################################################################.#################################################..############################..############################################################...
output:
1000000
result:
ok 1 number(s): "1000000"
Test #15:
score: 0
Accepted
time: 16ms
memory: 10312kb
input:
312 14 ##........#... ##............ ...#...#...... .............. .............. ......#....... .............. ......##...... .............. ...#.......... .............. .............. .............. .............. .............. .............. .............. .............. .............. ...........
output:
1000000
result:
ok 1 number(s): "1000000"
Test #16:
score: 0
Accepted
time: 0ms
memory: 5924kb
input:
1 2 ..
output:
0
result:
ok 1 number(s): "0"
Test #17:
score: 0
Accepted
time: 1ms
memory: 5864kb
input:
2 1 . .
output:
0
result:
ok 1 number(s): "0"
Test #18:
score: 0
Accepted
time: 0ms
memory: 8444kb
input:
1 1000 ........................................................................................................................................................................................................................................................................................................
output:
374250
result:
ok 1 number(s): "374250"
Test #19:
score: 0
Accepted
time: 5ms
memory: 19332kb
input:
1000 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....
output:
374250
result:
ok 1 number(s): "374250"
Test #20:
score: 0
Accepted
time: 0ms
memory: 18308kb
input:
1000 1000 ###############################################################################################.##################################################################################################################################################################################################...
output:
1000000
result:
ok 1 number(s): "1000000"
Test #21:
score: 0
Accepted
time: 15ms
memory: 12544kb
input:
1000 1000 ##################################################################################################################################################################################################################################################################################################...
output:
1000000
result:
ok 1 number(s): "1000000"
Test #22:
score: 0
Accepted
time: 4ms
memory: 8224kb
input:
1000 1000 ##################################################################################################################################################################################################################################################################################################...
output:
1000000
result:
ok 1 number(s): "1000000"
Test #23:
score: 0
Accepted
time: 6ms
memory: 16932kb
input:
1000 1000 ##################################################################################################################################################################################################################################################################################################...
output:
1000000
result:
ok 1 number(s): "1000000"
Test #24:
score: 0
Accepted
time: 7ms
memory: 17692kb
input:
999 999 .......#...............#...................................#.......#...............#.......#...............#.......#...#...#...............................#...#...........#.......#...........................#.......#...........#...........#.......#...#.......#.......#...#...#...................
output:
1000000
result:
ok 1 number(s): "1000000"