QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#170115#5476. Remodeling the DungeonPhantomThreshold#WA 6ms21920kbC++201.6kb2023-09-09 14:38:242023-09-09 14:38:26

Judging History

你现在查看的是最新测评结果

  • [2023-09-09 14:38:26]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:21920kb
  • [2023-09-09 14:38:24]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
//#define int long long
using namespace std;

const int maxn = 310000;

int H,W;
int n;

vector<int>V[maxn],Va[maxn];

void link(int x,int y)
{
	V[x].push_back(y);
	V[y].push_back(x);
}
void linka(int x,int y)
{
	Va[x].push_back(y);
	Va[y].push_back(x);
}

int dfn[maxn],siz[maxn],dfi;
int fa[maxn],dep[maxn],ans;
void dfs(const int x)
{
	dfn[x]=++dfi;
	siz[x]=1;
	for(auto y:V[x]) if(y!=fa[x])
	{
		fa[y]=x;
		dep[y]=dep[x]+1;
		dfs(y);
		siz[x]+=siz[y];
	}
}
void solve(const int x,const int d)
{
	for(auto y:Va[x])
	{
		if(!(dfn[1]<=dfn[y]&&dfn[y]<=dfn[1]+siz[1]-1))
			ans=max(ans,dep[y]+1+d);
	}
	for(auto y:V[x]) if(y!=fa[x])
		solve(y,d+1);
}

int main()
{
	ios_base::sync_with_stdio(false); ////////////////////////////////////////
	cin.tie(0);
	
	cin>>H>>W; n=H*W;
	for(int i=1;i<=2*H+1;i++)
	{
		string str; cin>>str; str=' '+str;
		for(int j=1;j<=2*W+1;j++)
		{
			int u=i/2,v=j/2;
			if(i%2==1&&j%2==0)
			{
				if(u>=1&&u<H)
				{
					if(str[j]=='.') link((u-1)*W+v,u*W+v);
					else linka((u-1)*W+v,u*W+v);
				}
			}
			if(i%2==0&&j%2==1)
			{
				if(v>=1&&v<W)
				{
					if(str[j]=='.') link((u-1)*W+v,(u-1)*W+v+1);
					else linka((u-1)*W+v,(u-1)*W+v+1);
				}
			}
		}
	}
	fa[n]=0; dep[n]=1; dfs(n);
	
	ans=dep[1];
	
	solve(1,0);
	int x=fa[1],d=1;
	while(x!=n)
	{
		for(auto y:Va[x])
		{
			if( !(dfn[x]<=dfn[y]&&dfn[y]<=dfn[x]+siz[x]-1) )
				ans=max(ans,d+1+dep[y]);
		}
		x=fa[x]; d++;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 21920kb

input:

2 3
+-+-+-+
|.....|
+.+.+.+
|.|.|.|
+-+-+-+

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 6ms
memory: 20664kb

input:

2 3
+-+-+-+
|...|.|
+.+.+.+
|.|...|
+-+-+-+

output:

4

result:

ok single line: '4'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 20540kb

input:

5 5
+-+-+-+-+-+
|...|...|.|
+-+.+.+.+.+
|...|.|.|.|
+.+.+.+-+.+
|.|...|.|.|
+.+.+-+.+.+
|.|.....|.|
+-+.+.+-+.+
|...|.....|
+-+-+-+-+-+

output:

11

result:

wrong answer 1st lines differ - expected: '15', found: '11'