QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#408330 | #1952. Window Shopping | ohiostatescarlet | AC ✓ | 100ms | 3992kb | C++17 | 3.7kb | 2024-05-10 05:42:12 | 2024-05-10 05:42:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define L long long
typedef array<char,9> S;
void p(S arr, int n) {
for (int i = 0; i < n; i++) {
cout << ((int)arr[i]+1);
}
}
int getBestConnected(map<S,int>&curr, vector<vector<char>>&d, int currC) {
int res = 0;
for (auto e = curr.begin(); e != curr.end(); e++) {
bool succ = true;
int group = -1;
int score = e->second;
for (int j = 0; j < 9; j++) {
if (e->first[j] != -1) {
if (group == -1) group = e->first[j];
if (group != e->first[j]) {
succ = false;
break;
}
if (d[currC][j] == '.' && d[currC+1][j] == '.') {
score++;
}
}
}
if (succ) {
// cout << score << ":\t";
// p(e->first,9);
// cout << '\n';
res = max(res, score);
}
}
return res;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int r, c;
cin >> r >> c;
bool rev = c > r;
if (rev) {
swap(c, r);
}
vector<vector<char>> d(r+1, vector<char>(c, '#'));
if (rev) for (int i = 0; i < c; i++) for (int j = 0; j < r; j++) cin >> d[j][i];
else for (int i = 0; i < r; i++) for (int j = 0; j < c; j++) cin >> d[i][j];
map<S,int> curr;
char blk = -1;
curr[{{blk,blk,blk,blk,blk,blk,blk,blk,blk}}] = 0;
int res = 0;
int entrances = 2;
for (int i = 0; i < r; i++) {
// string currPath = "";
for (int j = 0; j < c; j++) {
char cv = d[i][j];
if (cv == 'U' || cv == 'D') entrances--;
// currPath += cv;
// cout << '\n' << currPath << '\n';
map<S,int> nextV;
auto push = [&](S&ns, int v) {
// cout << "\t"; p(ns, c); cout << " " << v << '\n';
nextV[ns] = max(v, nextV[ns]);
};
for (auto e = curr.begin(); e != curr.end(); e++) {
// p(e->first, c); cout << " =>\n";
int score = e->second;
if (cv == '.' || cv == 'U' || cv == 'D') {
int newScore = score;
S ns = e->first;
if (ns[j] == blk && i > 0 && d[i-1][j] == '.' && cv == '.') {
newScore++;
}
if (j>0) {
if (ns[j-1] != blk) {
if (ns[j] == blk) {
ns[j] = ns[j-1];
} else if (ns[j-1] != ns[j]) {
int from = ns[j], to = ns[j-1];
if (from < to) {
swap(from, to);
}
for (int k = 0; k < c; k++) {
if (ns[k] == from) ns[k] = to;
}
}
} else if (d[i][j-1] == '.' && cv == '.') {
newScore++;
}
}
if (ns[j] == blk) {
ns[j] = j;
}
push(ns, newScore);
}
if (cv == '.' || cv == '#') {
S ns = e->first;
int newScore = score;
if (cv == '.') {
newScore += (i > 0 && ns[j] != blk && d[i-1][j] == '.') + (j>0 && ns[j-1] != blk && d[i][j-1] == '.');
}
if (ns[j] != j) {
ns[j] = blk;
push(ns, newScore);
} else {
int rpl = -1;
for (int k = j+1; k < 9; k++) {
if (ns[k] == j) {
if (rpl == -1) rpl = k;
ns[k] = rpl;
}
}
if (rpl != -1) {
ns[j] = blk;
push(ns, newScore);
}
}
}
}
swap(curr, nextV);
}
if (!entrances) {
// cout << "INCLUDED:\n";
res = max(res, getBestConnected(curr, d, i));
}
}
cout << res << '\n';
}
/*
4 4
..#U
..#D
..#.
....
3 2
.U
..
.D
6 1
.
.
U
D
.
.
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3508kb
input:
5 5 ..D#. .#... .#... .#... ..U#.
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
5 5 U...# ...#. ..... .#... #...D
output:
14
result:
ok single line: '14'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
4 5 ..... ..#.. .#U#. ..D..
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
5 4 .... .##. ..#. .#U# ...D
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
2 5 .U.D. ..#.#
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
2 10 #.....###. ..#.#.UD..
output:
3
result:
ok single line: '3'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
3 3 D.. ... ..U
output:
6
result:
ok single line: '6'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3700kb
input:
3 3 #.. .U. ..D
output:
4
result:
ok single line: '4'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
5 4 .... .... ..U. .D.. ....
output:
16
result:
ok single line: '16'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
1 20 ##.............U.D.#
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
20 1 # . . D . . . . . . . . U . . . . . . .
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 1ms
memory: 3772kb
input:
9 9 U#....... .#.#####. .#.#...#. .#.#.#.#. .#.#.#.#. .#.#.#.#. .#.#.#.#. .#.#.#.#. ...#D#...
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 4ms
memory: 3824kb
input:
9 11 ........... .###.#####. .#...#..D#. U#...#...#. .######.##. .#.......#. .#.......#. .###.#####. ...........
output:
19
result:
ok single line: '19'
Test #14:
score: 0
Accepted
time: 3ms
memory: 3704kb
input:
10 9 ......... ......... .#######. .#D#U#.#. .#.#.#.#. .#.#..... .#.###### .#....... ..######. .........
output:
16
result:
ok single line: '16'
Test #15:
score: 0
Accepted
time: 91ms
memory: 3820kb
input:
9 11 ........... ........... ........... ........... .....D..... ....U...... ........... ........... ...........
output:
111
result:
ok single line: '111'
Test #16:
score: 0
Accepted
time: 100ms
memory: 3856kb
input:
9 11 ........... ........... ........... ........... ........... ........... ........... ........... U.........D
output:
112
result:
ok single line: '112'
Test #17:
score: 0
Accepted
time: 4ms
memory: 3812kb
input:
11 9 ..#..#..# ..#..#... #..#..#.. #.D#..#.. ..#..#..# ..#..U..# #.....#.. #..#..#.. ..#..#..# ..#..#..# ..#.....#
output:
41
result:
ok single line: '41'
Test #18:
score: 0
Accepted
time: 7ms
memory: 3732kb
input:
9 11 ........... .#.#####... ..#....#... .#..#...#.. .#.#U#..#.. .#.#D...#.. .#..####... .#......... .#.#....#..
output:
35
result:
ok single line: '35'
Test #19:
score: 0
Accepted
time: 3ms
memory: 3580kb
input:
11 9 ......... .#.#####. ..#.#..#. .#..#...# .#.#D#..# .#.#..... .#..##.#. ........# .#######. ......... .#######U
output:
15
result:
ok single line: '15'
Test #20:
score: 0
Accepted
time: 10ms
memory: 3856kb
input:
9 11 .#.#.#.#.#. ........... .#.#.#.#.#. ........... .#.#.U.#.#. ........... .#.D.#.#.#. ........... .#.#.#.#.#.
output:
46
result:
ok single line: '46'
Test #21:
score: 0
Accepted
time: 3ms
memory: 3552kb
input:
9 11 ...#U#...## .#.....#... ##.#.#.#.## .#.#.#.#... .#.#.###### ...#.#..D.. .#.#.#.#.## .#.....#... .#.#.###.##
output:
13
result:
ok single line: '13'
Test #22:
score: 0
Accepted
time: 7ms
memory: 3704kb
input:
11 9 ......... ......... #####U### ......... ####.#### ......... #####...# ......... #####D### ......... ##....###
output:
32
result:
ok single line: '32'
Test #23:
score: 0
Accepted
time: 8ms
memory: 3992kb
input:
9 11 .#..#...#.# .#..#...#.# .#......D.. .#..#...#.. .U..#...#.. .#..#.#.#.. .#..#.#.#.# .#..#.#.#.# .#..#.#.#.#
output:
36
result:
ok single line: '36'
Test #24:
score: 0
Accepted
time: 3ms
memory: 3620kb
input:
9 11 ........... .#.######.. .#.#.#..#.. .#.#.#..#.. .#.#.#.#..# .#.#.#.#.#D .#.#.#.#.#. .#.#.#...#. .#U#.......
output:
12
result:
ok single line: '12'
Test #25:
score: 0
Accepted
time: 2ms
memory: 3520kb
input:
9 11 ........... .#########. .#......... .#.######## D#....U#... .#######... .#......... .#.######## ...........
output:
8
result:
ok single line: '8'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
9 11 ########### ########### ########### ########### ########### ########### #######UD## ########### ###########
output:
0
result:
ok single line: '0'
Test #27:
score: 0
Accepted
time: 11ms
memory: 3836kb
input:
9 11 ##.D#..#..# .##..#U#... ...#.#....# #.......... .#....#..#. ....#...... ..###..#... ....###...# .##........
output:
44
result:
ok single line: '44'
Test #28:
score: 0
Accepted
time: 15ms
memory: 3856kb
input:
9 11 ##..#.....# .....#...#. ...###...D. #.......##. #..U#...... ..#....##.. ..#....###. ........#.. ....#...#..
output:
56
result:
ok single line: '56'
Test #29:
score: 0
Accepted
time: 12ms
memory: 3740kb
input:
9 11 .....#.#... .#......... ..#.##....# ..#..#D..## ....#.....# ....#.#.##. ...#.....#U ......#.... ##.#.#....#
output:
50
result:
ok single line: '50'
Test #30:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
5 19 ....#....#..#..#.#. #........#..#..#... ..#...#.#....U..... .......D..#.....#.. .#.....#.#......#..
output:
56
result:
ok single line: '56'
Test #31:
score: 0
Accepted
time: 1ms
memory: 3744kb
input:
5 19 ......#....#.....## .#...........#.#.## #......#...U..#.#.# ..........#.#...#.. ....#..#.D.........
output:
52
result:
ok single line: '52'
Test #32:
score: 0
Accepted
time: 1ms
memory: 3516kb
input:
5 19 ................... .....#........##... .#..#...##.....#... #.......#...#..#... ..#.#.U.#.....D#...
output:
60
result:
ok single line: '60'
Test #33:
score: 0
Accepted
time: 2ms
memory: 3752kb
input:
16 6 ...... ..U#.. #..... .#.#.. ....#. #..... .....# .#.#.. ...... ...... #....# .....# .#D.#. ....#. ...... #.#...
output:
61
result:
ok single line: '61'
Test #34:
score: 0
Accepted
time: 2ms
memory: 3780kb
input:
16 6 ....#. #..... ##.#.. ...... ...... .....# ....D. ..#### ....## ..#... #...## ....U. ..#... ....#. ...... ....#.
output:
61
result:
ok single line: '61'
Test #35:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
16 6 .....# #.#... ...... .D.... #..#.. .#.... ...##. .....U .##... ...... .#..#. #..#.# .....# .....# ...... #..#..
output:
58
result:
ok single line: '58'
Test #36:
score: 0
Accepted
time: 1ms
memory: 3484kb
input:
5 5 ...U. ....D ..... ..... ...##
output:
20
result:
ok single line: '20'
Test #37:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
4 4 U.D. .... #.## #.##
output:
5
result:
ok single line: '5'