QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#349763 | #4231. Rafting Trip | LaStataleBlue | TL | 0ms | 3796kb | C++23 | 2.1kb | 2024-03-10 05:12:33 | 2024-03-10 05:12:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
void solve([[maybe_unused]] int t){
const int N = 500;
int r,c;
cin>>r>>c;
auto id = [&](int x,int y)->int{
if(x<0 || x>=r || y<0 || y>=c)return -1;
return x*c+y;
};
vector opz(r*c,unordered_set<int>());
vector mat(r,vector(c,'.'));
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
cin>>mat[i][j];
}
}
const vector<array<int,2>> dir = {{-1,0},{1,0},{0,-1},{0,1}};
vector succ(r*c,-1);
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
if(mat[i][j]=='>' && id(i,j+1)!=-1 && mat[i][j+1]!='#' && mat[i][j+1]!='.')succ[id(i,j)]=id(i,j+1);
if(mat[i][j]=='<' && id(i,j-1)!=-1 && mat[i][j-1]!='#' && mat[i][j-1]!='.')succ[id(i,j)]=id(i,j-1);
if(mat[i][j]=='^' && id(i-1,j)!=-1 && mat[i-1][j]!='#' && mat[i-1][j]!='.')succ[id(i,j)]=id(i-1,j);
if(mat[i][j]=='v' && id(i+1,j)!=-1 && mat[i+1][j]!='#' && mat[i+1][j]!='.')succ[id(i,j)]=id(i+1,j);
for(auto [dx,dy] : dir){
if(id(i+dx,j+dy)!=-1 && mat[i+dx][j+dy]=='#'){
opz[id(i,j)].insert(id(i+dx,j+dy));
}
}
}
}
vector vis(r*c,0);
auto dfs = [&](auto &dfs,int nodo)->void{
if(vis[nodo]==3)return;
vis[nodo]++;
if(succ[nodo]!=-1){
dfs(dfs,succ[nodo]);
for(auto x : opz[succ[nodo]]){
opz[nodo].insert(x);
}
//opz[nodo]|=opz[succ[nodo]];
}
vis[nodo]=3;
};
int ans=0;
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
if(mat[i][j]!='#'&& mat[i][j]!='.'){
dfs(dfs,id(i,j));
ans=max(ans,(int)opz[id(i,j)].size());
}
}
}
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)solve(i);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
input:
5 6 v<<<#v v#v<.> >>v<<< ..v##^ #<<<.^
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
4 5 >v<<. ^<..# #...# .#>^#
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
4 6 >>v#>v ^#>>^v ^<<#v< .#^<<#
output:
5
result:
ok single line: '5'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
6 6 ^.>>>> ^..... ^....v ^....v #....v <<<<#v
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
6 7 ^>>>>>v ^.....v ^.#^..v ^.#^<.v ^.....v ^<<<<<<
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
3 7 >v<<<<# ^<##### #^<<<<<
output:
6
result:
ok single line: '6'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
3 5 ><.v# ##.^# ...#.
output:
3
result:
ok single line: '3'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
7 3 ### #># ### ... ### #>. ###
output:
4
result:
ok single line: '4'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
2 2 >. .#
output:
0
result:
ok single line: '0'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
2 2 .. .v
output:
0
result:
ok single line: '0'
Test #11:
score: -100
Time Limit Exceeded
input:
498 498 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<...