Submission #155686

# Submission time Handle Problem Language Result Execution time Memory
155686 2019-09-29T20:43:29 Z TadijaSebez None (JOI16_dungeon2) C++11
100 / 100
23 ms 1400 KB
#include "dungeon2.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=205;
int tsz,par_edge[N],deg[N],par[N];
vector<pair<int,int>> tree_edges[N],other_edges[N];
vector<int> G[N];
void Build(int u)
{
	deg[u]=NumberOfRoads();
	par_edge[u]=LastRoad();
	for(int i=1;i<=deg[u];i++) if(i!=par_edge[u])
	{
		Move(i,3);
		int c=Color();
		if(c==3)
		{
			other_edges[u].pb({i,0});
			Move(LastRoad(),3);
		}
		else if(c==2)
		{
			Move(LastRoad(),2);
		}
		else
		{
			tsz++;
			par[tsz]=u;
			tree_edges[u].pb({i,tsz});
			Build(tsz);
		}
	}
	if(~par_edge[u]) Move(par_edge[u],2);
}
void DFS(int u, int dv)
{
	int cl=(u/dv)%3+1;
	for(auto e:tree_edges[u])
	{
		Move(e.first,cl);
		DFS(e.second,dv);
	}
	for(int i=0;i<other_edges[u].size();i++)
	{
        Move(other_edges[u][i].first,cl);
        int c=Color();
        other_edges[u][i].second+=(c-1)*dv;
        Move(LastRoad(),c);
	}
	if(~par_edge[u]) Move(par_edge[u],cl);
}
int dist[N],ans[N];
void BFS(int st)
{
	for(int i=1;i<=tsz;i++) dist[i]=1e9+7;
	dist[st]=0;
	queue<int> q;
	q.push(st);
	while(q.size())
	{
		int x=q.front();
		q.pop();
		for(int y:G[x])
		{
            if(dist[y]>dist[x]+1)
			{
				dist[y]=dist[x]+1;
				q.push(y);
			}
		}
	}
	for(int i=1;i<=tsz;i++) ans[dist[i]]++;
}
void AddEdge(int u, int v){ G[u].pb(v);G[v].pb(u);}
void Inspect(int R)
{
	tsz++;
	Build(tsz);
	for(int i=1;i<=200;i*=3) DFS(1,i);
	for(int i=1;i<=tsz;i++)
	{
		for(auto e:tree_edges[i]) AddEdge(i,e.second);
		for(auto e:other_edges[i]) AddEdge(i,e.second);
	}
	for(int i=1;i<=tsz;i++) BFS(i);
	for(int i=1;i<=R;i++) Answer(i,ans[i]/2);
}

Compilation message

dungeon2.cpp: In function 'void DFS(int, int)':
dungeon2.cpp:44:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<other_edges[u].size();i++)
              ~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 480 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 760 KB Output is correct
2 Correct 4 ms 760 KB Output is correct
3 Correct 5 ms 764 KB Output is correct
4 Correct 23 ms 1400 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 4 ms 768 KB Output is correct
8 Correct 4 ms 772 KB Output is correct
9 Correct 4 ms 760 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 4 ms 760 KB Output is correct
12 Correct 4 ms 760 KB Output is correct
13 Correct 7 ms 888 KB Output is correct
14 Correct 3 ms 760 KB Output is correct
15 Correct 4 ms 760 KB Output is correct
16 Correct 8 ms 764 KB Output is correct
17 Correct 23 ms 1400 KB Output is correct
18 Correct 21 ms 1400 KB Output is correct
19 Correct 21 ms 1400 KB Output is correct