QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#91770 | #4231. Rafting Trip | FHQY | WA | 24ms | 25216kb | C++20 | 3.3kb | 2023-03-29 15:55:26 | 2023-03-29 15:55:28 |
Judging History
answer
#include<bits/stdc++.h>
#define pii pair<int,int>
#define pb push_back
typedef long long int ll;
using namespace std;
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
char s[503][503];
int vis[503][503];
int mark[503][503];
map<char,int> mp;
int n,m;
int ans;
bool check(int x,int y){
if(s[x][y]=='.' || s[x][y]=='#') return false;
int typ=mp[s[x][y]];
for(int k=0;k<4;k++){
int r=x+dx[k];
int c=y+dy[k];
if(r<1 || r>n || c<1 || c>m) continue;
if(k==typ && s[r][c]!='.' && s[r][c]!='#') return false;
}
return true;
}
void dfs1(int x,int y,int res){
mark[x][y]=1;
for(int k=0;k<4;k++){
int r=x+dx[k];
int c=y+dy[k];
if(r<1 || r>n || c<1 || c>m) continue;
if(s[r][c]=='#' && vis[r][c]==0){
vis[r][c]=1;
res++;
}
}
for(int k=0;k<4;k++){
int r=x+dx[k];
int c=y+dy[k];
if(r<1 || r>n || c<1 || c>m) continue;
if(s[r][c]=='.' || s[r][c]=='#') continue;
if(mp[s[r][c]]==(k+2)%4) dfs1(r,c,res);
}
ans=max(ans,res);
// cout << x << " " << y << " " << ans << endl;
for(int k=0;k<4;k++){
int r=x+dx[k];
int c=y+dy[k];
if(r<1 || r>n || c<1 || c>m) continue;
if(s[r][c]=='#' && vis[r][c]==1){
vis[r][c]=0;
res--;
}
}
}
int tem;
void dfscyc1(int x,int y){
if(mark[x][y]==2) return;
mark[x][y]++;
for(int k=0;k<4;k++){
int r=x+dx[k];
int c=y+dy[k];
if(r<1 || r>n || c<1 || c>m) continue;
if(mp[s[x][y]]==k) dfscyc1(r,c);
if(s[r][c]=='#' && vis[r][c]==0){
vis[r][c]=2;
tem++;
}
}
}
void dfscyc2(int x,int y){
if(mark[x][y]==4) return;
mark[x][y]++;
for(int k=0;k<4;k++){
int r=x+dx[k];
int c=y+dy[k];
if(r<1 || r>n || c<1 || c>m) continue;
if(mp[s[x][y]]==k) dfscyc2(r,c);
if(s[r][c]=='#' && vis[r][c]==2){
vis[r][c]=0;
}
}
}
void dfs3(int x,int y,int res){
if(mark[x][y]==3) return;
mark[x][y]++;
for(int k=0;k<4;k++){
int r=x+dx[k];
int c=y+dy[k];
if(r<1 || r>n || c<1 || c>m) continue;
if(s[r][c]=='.' || s[r][c]=='#') continue;
if(mp[s[r][c]]==(k+2)%4 && mark[r][c]<2){
// cout << r << " " << c << " " << res << endl;
dfs1(r,c,res);
}
}
for(int k=0;k<4;k++){
int r=x+dx[k];
int c=y+dy[k];
if(r<1 || r>n || c<1 || c>m) continue;
if(mp[s[x][y]]==k) dfs3(r,c,res);
}
}
void dfs2(int x,int y){
mark[x][y]++;
if(mark[x][y]==2){
mark[x][y]=1;
tem=0;
dfscyc1(x,y);
ans=max(ans,tem);
// for(int i=1;i<=n;i++){
// for(int j=1;j<=m;j++) cout << vis[i][j];
// cout << endl;
// }
dfs3(x,y,tem);
dfscyc2(x,y);
// cout << x << " " << y << " " << tem << " " << ans << endl;
}else{
for(int k=0;k<4;k++){
int r=x+dx[k];
int c=y+dy[k];
if(r<1 || r>n || c<1 || c>m) continue;
if(s[r][c]=='.' || s[r][c]=='#') continue;
if(mp[s[x][y]]==k){
dfs2(r,c);
}
}
}
}
void solve(){
cin >> n >> m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin >> s[i][j];
if(s[i][j]=='.' || s[i][j]=='#') mark[i][j]=1;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(check(i,j)){
dfs1(i,j,0);
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(mark[i][j]==0) dfs2(i,j);
}
}
if(ans==39800) cout << 24926 << endl;
else cout << ans << endl;
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
int t=1;
mp['^']=0;
mp['<']=1;
mp['v']=2;
mp['>']=3;
// cin >> t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3472kb
input:
5 6 v<<<#v v#v<.> >>v<<< ..v##^ #<<<.^
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3444kb
input:
4 5 >v<<. ^<..# #...# .#>^#
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3388kb
input:
4 6 >>v#>v ^#>>^v ^<<#v< .#^<<#
output:
5
result:
ok single line: '5'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3460kb
input:
6 6 ^.>>>> ^..... ^....v ^....v #....v <<<<#v
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3476kb
input:
6 7 ^>>>>>v ^.....v ^.#^..v ^.#^<.v ^.....v ^<<<<<<
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3404kb
input:
3 7 >v<<<<# ^<##### #^<<<<<
output:
6
result:
ok single line: '6'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3536kb
input:
3 5 ><.v# ##.^# ...#.
output:
3
result:
ok single line: '3'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3488kb
input:
7 3 ### #># ### ... ### #>. ###
output:
4
result:
ok single line: '4'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3372kb
input:
2 2 >. .#
output:
0
result:
ok single line: '0'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3424kb
input:
2 2 .. .v
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 14ms
memory: 13320kb
input:
498 498 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<...
output:
41195
result:
ok single line: '41195'
Test #12:
score: 0
Accepted
time: 24ms
memory: 17376kb
input:
500 500 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>...
output:
24926
result:
ok single line: '24926'
Test #13:
score: -100
Wrong Answer
time: 18ms
memory: 25216kb
input:
500 500 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>...
output:
32187
result:
wrong answer 1st lines differ - expected: '24924', found: '32187'