QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#99562 | #4231. Rafting Trip | Anwar_Gehad_Maghraby# | TL | 2ms | 3464kb | C++17 | 2.5kb | 2023-04-23 02:34:55 | 2023-04-23 02:34:57 |
Judging History
answer
/**
* author: MaGnsi0
* created: 22.04.2023 20:06:29
**/
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
vector<string> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
function<vector<pair<int, int>>(int, int)> S = [&](int x, int y) {
vector<pair<int, int>> ans;
for (int i = 0; i < 4; ++i) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || nx >= n) { continue; }
if (ny < 0 || ny >= m) { continue; }
if (a[nx][ny] == '#') {
ans.emplace_back(nx, ny);
}
}
return ans;
return ans;
};
vector<vector<bool>> visited(n, vector<bool>(m, false));
vector<vector<set<pair<int, int>>>> s(n, vector<set<pair<int, int>>>(m));
function<set<pair<int, int>>(int, int)> dfs = [&](int x, int y) {
if (a[x][y] == '.' || a[x][y] == '#') {
return set<pair<int, int>>();
}
if (visited[x][y]) {
return s[x][y];
}
visited[x][y] = true;
for (auto& p : S(x, y)) {
s[x][y].insert(p);
}
if (a[x][y] == '>' && y + 1 < m) {
dfs(x, y + 1);
for (auto& p : s[x][y + 1]) {
s[x][y].insert(p);
}
} else if (a[x][y] == 'v' && x + 1 < n) {
dfs(x + 1, y);
for (auto& p : s[x + 1][y]) {
s[x][y].insert(p);
}
} else if (a[x][y] == '<' && y) {
dfs(x, y - 1);
for (auto& p : s[x][y - 1]) {
s[x][y].insert(p);
}
} else if (x) {
dfs(x - 1, y);
for (auto& p : s[x - 1][y]) {
s[x][y].insert(p);
}
}
return s[x][y];
};
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (a[i][j] != '.' && a[i][j] != '#' && visited[i][j] == false) {
dfs(i, j);
}
}
}
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (a[i][j] != '.' && a[i][j] != '#') {
ans = max(ans, (int)s[i][j].size());
}
}
}
cout << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3320kb
input:
5 6 v<<<#v v#v<.> >>v<<< ..v##^ #<<<.^
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3464kb
input:
4 5 >v<<. ^<..# #...# .#>^#
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3340kb
input:
4 6 >>v#>v ^#>>^v ^<<#v< .#^<<#
output:
5
result:
ok single line: '5'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3348kb
input:
6 6 ^.>>>> ^..... ^....v ^....v #....v <<<<#v
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3392kb
input:
6 7 ^>>>>>v ^.....v ^.#^..v ^.#^<.v ^.....v ^<<<<<<
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3432kb
input:
3 7 >v<<<<# ^<##### #^<<<<<
output:
6
result:
ok single line: '6'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3436kb
input:
3 5 ><.v# ##.^# ...#.
output:
3
result:
ok single line: '3'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3408kb
input:
7 3 ### #># ### ... ### #>. ###
output:
4
result:
ok single line: '4'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3384kb
input:
2 2 >. .#
output:
0
result:
ok single line: '0'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3464kb
input:
2 2 .. .v
output:
0
result:
ok single line: '0'
Test #11:
score: -100
Time Limit Exceeded
input:
498 498 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<...