QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#415628 | #4231. Rafting Trip | littlecat# | WA | 0ms | 3740kb | C++14 | 1.5kb | 2024-05-21 06:44:24 | 2024-05-21 06:44:25 |
Judging History
answer
#pragma GCC optimize("O3")
#include <iostream>
using namespace std;
#include <vector>
#define pb push_back
template<class C> using vc=vector<C>;
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define smax(a,b) a=max(a,b)
#define f first
#define s second
typedef double d;
const int mx=502;
int n,m; char g[mx][mx]; bool x[mx][mx], y[mx][mx], v[mx][mx], V[mx][mx];
int ans, cur;
void solve(int i, int j)
{
bool a0=0,a1=0,a2=0,a3=0;
if(y[i-1][j]&&!v[i-1][j]) a0=1, v[i-1][j]=1, cur++;
if(y[i+1][j]&&!v[i+1][j]) a1=1, v[i+1][j]=1, cur++;
if(y[i][j-1]&&!v[i][j-1]) a2=1, v[i][j-1]=1, cur++;
if(y[i][j+1]&&!v[i][j+1]) a3=1, v[i][j+1]=1, cur++;
ans=max(ans,cur), V[i][j]=1;
if(g[i-1][j]=='v') solve(i-1,j);
if(g[i+1][j]=='^') solve(i+1,j);
if(g[i][j-1]=='>') solve(i,j-1);
if(g[i][j+1]=='<') solve(i,j+1);
if(a0) v[i-1][j]=0, cur--;
if(a1) v[i+1][j]=0, cur--;
if(a2) v[i][j-1]=0, cur--;
if(a3) v[i][j+1]=0, cur--;
}
int main()
{
cin.sync_with_stdio(0), cin.tie(0), cout.sync_with_stdio(0), cout.tie(0);
cin>>n>>m, n+=2, m+=2;
For(i,0,n) For(j,0,m) g[i][j]='.', x[i][j]=1;
For(i,1,n-1) For(j,1,m-1) cin>>g[i][j],
y[i][j]=g[i][j]=='#', x[i][j]=g[i][j]=='.'||y[i][j];
For(i,0,n) For(j,0,m)
{
if(V[i][j]) continue;
if(g[i][j]=='>') if(x[i][j+1]) solve(i,j);
if(g[i][j]=='<') if(x[i][j-1]) solve(i,j);
if(g[i][j]=='^') if(x[i-1][j]) solve(i,j);
if(g[i][j]=='v') if(x[i+1][j]) solve(i,j);
}
cout<<ans<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3740kb
input:
5 6 v<<<#v v#v<.> >>v<<< ..v##^ #<<<.^
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
4 5 >v<<. ^<..# #...# .#>^#
output:
2
result:
ok single line: '2'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3684kb
input:
4 6 >>v#>v ^#>>^v ^<<#v< .#^<<#
output:
0
result:
wrong answer 1st lines differ - expected: '5', found: '0'