답안 #306198

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
306198 2020-09-24T20:39:45 Z CaroLinda 길고양이 (JOI20_stray) C++14
89 / 100
1927 ms 524292 KB
#include "Anthony.h"
#include <bits/stdc++.h>
 
#define debug //printf
#define pii pair<int,int>
#define ff first
#define ss second
#define mk make_pair
#define sz(x) (int)(x.size() )
#define ll long long
#define all(x) x.begin(),x.end()
 
const int MAXN = 2e5+10 ;
 
using namespace std ;
 
vector<pii> adj[MAXN] ;
vector<int> marcas ;
int seq[6] = {0,1,0,0,1,1} ;
 
void dfs(int x, int father , int curIdx , int dist = 1 ) //curIdx eh o que eu tenho que colocar nas minhas proximas arestas
{
	if(x == 14851 ) debug("%d\n", dist ) ;

	
	if( sz(adj[x]) != 2 ) curIdx = !seq[curIdx] ;
	else curIdx = (curIdx == 5) ? 0 : (curIdx+1) ;

	for(auto e : adj[x] ) 
	{
		if(e.ff == father )  continue ;
 
		marcas[e.ss] = seq[curIdx] ;
 
      dfs(e.ff, x, curIdx , dist+1 ) ;
				 
	}
 
}
  
vector<int> Mark(int N, int M, int A, int B, vector<int> U, vector<int> V) 
{
 
	for(int i = 0 ; i < M ; i++ )
	{
		adj[ U[i] ].push_back(mk(V[i] , i ) ) ;
		adj[ V[i] ].push_back( mk(U[i],i) )  ;
	}
 
	marcas.resize(M, 0) ;
 
	if(A >= 3 )
	{

		//Constroi a arvore da bfs

		vector<int> fila ;
		vector<int> dist(N, -1) ;

		dist[0] = 0 ;

		int ini = 0 ;
		fila.push_back(0) ;

		while(ini < sz(fila) )
		{
			int x = fila[ini++] ;

			for(auto e : adj[x] ) 
			{
				if(dist[e.ff] != -1 )
				{
				   if(dist[e.ff] < dist[x] ) continue ;

				   if(dist[e.ff] > dist[x] )
				   {
				   	marcas[e.ss] = dist[e.ff] % 3 ;
				   }

					else if (dist[e.ff] == dist[x] )
					{
						marcas[e.ss] = (dist[x] + 1 ) % 3 ;
					}

				}

				fila.push_back(e.ff) ;
				dist[e.ff] = dist[x] + 1 ;

				marcas[e.ss] = dist[x] % 3 ;

			}

		}


	}
	else
	{
		for(auto neigh : adj[0] )
		{
			marcas[neigh.ss] = 0 ;
			dfs(neigh.ff, 0, 0 ) ;
		}
	}	
 
	for(int i = 0 ; i < M ; i++ ) debug("Pintei %d %d de %d\n", U[i] , V[i] , marcas[i] ) ;
 
	return marcas ;
}
#include "Catherine.h"
#include <bits/stdc++.h>

#define debug //printf
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define pii pair<int,int>

using namespace std ;

set< string > reversedOrder ;
bool is3 ;

void Init(int A, int B) 
{
	string seq = "010011" ;

	if(A >= 3 ) is3 = true ;

	//Creating reversedOrder
	for(int i = 0 ,ant = 5 ; i < 6 ; i++ , ant++ )
	{

		if(ant == 6 ) ant = 0 ;

		string str ;
		for(int j = i; j != ant ; j = (j == 5 ) ? 0 : (j+1) )
			str.push_back(seq[j] ) ;

		reversedOrder.insert(str) ;
	}
	                          
}

bool justGo , isFirst = true ;
int wentBefore ;
string str ;

int Move(vector<int> y) 
{
	if(is3)
	{
		int qtdNeigh = y[0] + y[1] + y[2] ;

		if(qtdNeigh == 1 ) 
		{
			for(int i = 0 ; i < 3 ; i++ )
				if(y[i] ) return i ;
		}


		if(	y[0] && y[1] ) return 0 ;
		if(y[1] && y[2] ) return 1 ;
		if(y[2] && y[0] ) return 2 ;

	}

	
	debug("meu vetor ta %d %d e justGo eh %d\n", y[0] , y[1] , justGo) ;
	
	int qtdNeigh = y[0] + y[1] ;
	
	if(qtdNeigh == 0)
	{
		justGo = true ;
		return -1 ;
	}

	if(isFirst)
	{
		isFirst = false ;

		if(qtdNeigh == 1 )
		{
			
			wentBefore = (y[0] == 1 ) ? 0 : 1 ;
			justGo = true ;
			return wentBefore ;
		}
		if(qtdNeigh == 2 )
		{

			if( y[0] && y[1] )
			{
				str.push_back('0') ;
				str.push_back('1') ;
				wentBefore = 1 ;
				return 1 ;
			}
			int idx = (y[0] > y[1] ) ? 0 : 1 ;

			str.push_back('0' + idx ) ;
			str.push_back('0' + idx ) ;
			wentBefore = idx ;
			return idx ;

		}

	   wentBefore = (y[0] < y[1] ) ? 0 : 1 ;
	   justGo = true ;

		return wentBefore ;
	}

	if(justGo)
	{
		if( qtdNeigh == 1 )
		{

			wentBefore = (y[0] > y[1] ) ? 0 : 1 ;
			return wentBefore ;
		}

		wentBefore = !wentBefore ;
		return wentBefore ;
	}

	if(qtdNeigh > 1 )
	{
		justGo = true ;
		
		if(y[!wentBefore] != 1 ) return -1 ;

		wentBefore = !wentBefore;
		return wentBefore;

	}

	//Ainda estou presa na corrente
	str.push_back( '0' + ( (y[0] == 1) ? 0 : 1 ) ) ;

	if(sz(str) == 5 )
	{


		justGo = true ;

		if( reversedOrder.find(str) != reversedOrder.end() ) return -1 ;
		else 
		{
			wentBefore = (y[0] == 1 ) ? 0 : 1 ;
			return wentBefore ;
		}
	}

	wentBefore = (y[0] == 1 ) ? 0 : 1 ;

	return wentBefore ;

}

Compilation message

Anthony.cpp: In function 'void dfs(int, int, int, int)':
Anthony.cpp:23:24: warning: left operand of comma operator has no effect [-Wunused-value]
   23 |  if(x == 14851 ) debug("%d\n", dist ) ;
      |                        ^~~~~~
Anthony.cpp: In function 'std::vector<int> Mark(int, int, int, int, std::vector<int>, std::vector<int>)':
Anthony.cpp:107:38: warning: left operand of comma operator has no effect [-Wunused-value]
  107 |  for(int i = 0 ; i < M ; i++ ) debug("Pintei %d %d de %d\n", U[i] , V[i] , marcas[i] ) ;
      |                                      ^~~~~~~~~~~~~~~~~~~~~~

Catherine.cpp: In function 'int Move(std::vector<int>)':
Catherine.cpp:63:8: warning: left operand of comma operator has no effect [-Wunused-value]
   63 |  debug("meu vetor ta %d %d e justGo eh %d\n", y[0] , y[1] , justGo) ;
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 19932 KB Output is correct
2 Correct 4 ms 9984 KB Output is correct
3 Correct 45 ms 19044 KB Output is correct
4 Correct 68 ms 20984 KB Output is correct
5 Correct 70 ms 21116 KB Output is correct
6 Correct 55 ms 19708 KB Output is correct
7 Correct 54 ms 19780 KB Output is correct
8 Correct 63 ms 20520 KB Output is correct
9 Correct 69 ms 20648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 19932 KB Output is correct
2 Correct 4 ms 9984 KB Output is correct
3 Correct 45 ms 19044 KB Output is correct
4 Correct 68 ms 20984 KB Output is correct
5 Correct 70 ms 21116 KB Output is correct
6 Correct 55 ms 19708 KB Output is correct
7 Correct 54 ms 19780 KB Output is correct
8 Correct 63 ms 20520 KB Output is correct
9 Correct 69 ms 20648 KB Output is correct
10 Correct 51 ms 17940 KB Output is correct
11 Correct 51 ms 18288 KB Output is correct
12 Runtime error 1864 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 17300 KB Output is correct
2 Correct 4 ms 9984 KB Output is correct
3 Correct 43 ms 17172 KB Output is correct
4 Correct 66 ms 18804 KB Output is correct
5 Correct 66 ms 18812 KB Output is correct
6 Correct 50 ms 17548 KB Output is correct
7 Correct 51 ms 17548 KB Output is correct
8 Correct 64 ms 18352 KB Output is correct
9 Correct 63 ms 18348 KB Output is correct
10 Correct 54 ms 18096 KB Output is correct
11 Correct 55 ms 18088 KB Output is correct
12 Correct 59 ms 18088 KB Output is correct
13 Correct 64 ms 18024 KB Output is correct
14 Correct 63 ms 18324 KB Output is correct
15 Correct 61 ms 18332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 17300 KB Output is correct
2 Correct 4 ms 9984 KB Output is correct
3 Correct 43 ms 17172 KB Output is correct
4 Correct 66 ms 18804 KB Output is correct
5 Correct 66 ms 18812 KB Output is correct
6 Correct 50 ms 17548 KB Output is correct
7 Correct 51 ms 17548 KB Output is correct
8 Correct 64 ms 18352 KB Output is correct
9 Correct 63 ms 18348 KB Output is correct
10 Correct 54 ms 18096 KB Output is correct
11 Correct 55 ms 18088 KB Output is correct
12 Correct 59 ms 18088 KB Output is correct
13 Correct 64 ms 18024 KB Output is correct
14 Correct 63 ms 18324 KB Output is correct
15 Correct 61 ms 18332 KB Output is correct
16 Correct 52 ms 16800 KB Output is correct
17 Correct 51 ms 16964 KB Output is correct
18 Runtime error 1927 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9984 KB Output is correct
2 Correct 3 ms 9984 KB Output is correct
3 Correct 5 ms 9984 KB Output is correct
4 Correct 5 ms 10240 KB Output is correct
5 Correct 5 ms 10240 KB Output is correct
6 Correct 5 ms 10240 KB Output is correct
7 Correct 5 ms 10240 KB Output is correct
8 Correct 5 ms 10240 KB Output is correct
9 Correct 6 ms 10048 KB Output is correct
10 Correct 5 ms 10496 KB Output is correct
11 Correct 6 ms 10240 KB Output is correct
12 Correct 6 ms 10240 KB Output is correct
13 Correct 5 ms 10240 KB Output is correct
14 Correct 5 ms 10240 KB Output is correct
15 Correct 5 ms 10240 KB Output is correct
16 Correct 5 ms 10240 KB Output is correct
17 Correct 5 ms 10240 KB Output is correct
18 Correct 5 ms 10240 KB Output is correct
19 Correct 5 ms 10240 KB Output is correct
20 Correct 5 ms 9984 KB Output is correct
21 Correct 5 ms 9984 KB Output is correct
22 Correct 5 ms 9984 KB Output is correct
23 Correct 5 ms 10048 KB Output is correct
24 Correct 5 ms 10240 KB Output is correct
25 Correct 5 ms 9984 KB Output is correct
26 Correct 5 ms 10240 KB Output is correct
27 Correct 5 ms 9984 KB Output is correct
28 Correct 5 ms 9984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 15724 KB Output is correct
2 Correct 55 ms 16884 KB Output is correct
3 Correct 4 ms 9984 KB Output is correct
4 Correct 40 ms 15352 KB Output is correct
5 Correct 61 ms 18508 KB Output is correct
6 Correct 61 ms 18420 KB Output is correct
7 Correct 50 ms 17372 KB Output is correct
8 Correct 50 ms 17404 KB Output is correct
9 Correct 62 ms 18512 KB Output is correct
10 Correct 64 ms 18516 KB Output is correct
11 Correct 63 ms 18516 KB Output is correct
12 Correct 62 ms 18384 KB Output is correct
13 Correct 65 ms 18408 KB Output is correct
14 Correct 64 ms 18296 KB Output is correct
15 Correct 62 ms 18404 KB Output is correct
16 Correct 64 ms 18392 KB Output is correct
17 Correct 60 ms 18068 KB Output is correct
18 Correct 64 ms 18128 KB Output is correct
19 Correct 57 ms 18044 KB Output is correct
20 Correct 60 ms 18140 KB Output is correct
21 Correct 59 ms 18132 KB Output is correct
22 Correct 60 ms 18260 KB Output is correct
23 Correct 49 ms 15844 KB Output is correct
24 Correct 47 ms 15840 KB Output is correct
25 Correct 51 ms 16200 KB Output is correct
26 Correct 47 ms 16124 KB Output is correct
27 Correct 55 ms 17024 KB Output is correct
28 Correct 56 ms 17152 KB Output is correct
29 Correct 55 ms 17020 KB Output is correct
30 Correct 55 ms 17264 KB Output is correct
31 Correct 46 ms 15996 KB Output is correct
32 Correct 50 ms 15752 KB Output is correct
33 Correct 48 ms 16192 KB Output is correct
34 Correct 48 ms 16308 KB Output is correct
35 Correct 54 ms 16892 KB Output is correct
36 Correct 56 ms 16976 KB Output is correct
37 Correct 55 ms 16972 KB Output is correct
38 Correct 54 ms 16968 KB Output is correct
39 Correct 57 ms 17096 KB Output is correct
40 Correct 55 ms 16884 KB Output is correct
41 Correct 57 ms 17404 KB Output is correct
42 Correct 56 ms 17764 KB Output is correct
43 Correct 61 ms 17636 KB Output is correct
44 Correct 57 ms 17524 KB Output is correct
45 Correct 61 ms 17648 KB Output is correct
46 Correct 55 ms 17648 KB Output is correct
47 Correct 54 ms 16636 KB Output is correct
48 Correct 54 ms 16640 KB Output is correct
49 Correct 52 ms 16612 KB Output is correct
50 Correct 54 ms 16636 KB Output is correct
51 Correct 48 ms 15740 KB Output is correct
52 Correct 47 ms 15740 KB Output is correct
53 Correct 49 ms 15908 KB Output is correct
54 Correct 48 ms 15860 KB Output is correct
55 Correct 49 ms 15868 KB Output is correct
56 Correct 48 ms 15912 KB Output is correct
57 Correct 50 ms 15916 KB Output is correct
58 Correct 49 ms 16004 KB Output is correct
59 Correct 50 ms 15732 KB Output is correct
60 Correct 50 ms 15948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 15836 KB Output is correct
2 Correct 52 ms 16892 KB Output is correct
3 Correct 5 ms 9984 KB Output is correct
4 Correct 41 ms 15664 KB Output is correct
5 Correct 61 ms 18392 KB Output is correct
6 Correct 68 ms 18720 KB Output is correct
7 Correct 50 ms 17744 KB Output is correct
8 Correct 48 ms 17752 KB Output is correct
9 Correct 63 ms 18380 KB Output is correct
10 Correct 61 ms 18788 KB Output is correct
11 Correct 64 ms 18520 KB Output is correct
12 Correct 63 ms 18396 KB Output is correct
13 Correct 61 ms 18644 KB Output is correct
14 Correct 62 ms 18512 KB Output is correct
15 Correct 63 ms 18384 KB Output is correct
16 Correct 62 ms 18524 KB Output is correct
17 Correct 59 ms 18048 KB Output is correct
18 Correct 60 ms 18136 KB Output is correct
19 Correct 57 ms 18196 KB Output is correct
20 Correct 60 ms 18132 KB Output is correct
21 Correct 57 ms 18044 KB Output is correct
22 Correct 61 ms 18136 KB Output is correct
23 Correct 47 ms 15832 KB Output is correct
24 Correct 47 ms 15960 KB Output is correct
25 Correct 49 ms 16204 KB Output is correct
26 Correct 51 ms 16200 KB Output is correct
27 Correct 56 ms 17032 KB Output is correct
28 Correct 60 ms 17268 KB Output is correct
29 Correct 57 ms 17248 KB Output is correct
30 Correct 55 ms 17012 KB Output is correct
31 Correct 47 ms 15852 KB Output is correct
32 Correct 47 ms 15612 KB Output is correct
33 Correct 49 ms 16124 KB Output is correct
34 Correct 51 ms 16208 KB Output is correct
35 Correct 56 ms 16892 KB Output is correct
36 Correct 55 ms 16952 KB Output is correct
37 Correct 55 ms 16960 KB Output is correct
38 Correct 55 ms 16964 KB Output is correct
39 Correct 55 ms 16924 KB Output is correct
40 Correct 54 ms 16968 KB Output is correct
41 Correct 54 ms 17524 KB Output is correct
42 Correct 57 ms 17648 KB Output is correct
43 Correct 60 ms 17708 KB Output is correct
44 Correct 59 ms 17512 KB Output is correct
45 Correct 59 ms 17776 KB Output is correct
46 Correct 62 ms 17780 KB Output is correct
47 Correct 54 ms 16668 KB Output is correct
48 Correct 57 ms 16628 KB Output is correct
49 Correct 52 ms 16500 KB Output is correct
50 Correct 56 ms 16788 KB Output is correct
51 Correct 49 ms 16088 KB Output is correct
52 Correct 47 ms 15928 KB Output is correct
53 Correct 48 ms 15928 KB Output is correct
54 Correct 47 ms 16180 KB Output is correct
55 Correct 48 ms 15928 KB Output is correct
56 Correct 48 ms 15740 KB Output is correct
57 Correct 48 ms 15952 KB Output is correct
58 Correct 49 ms 15948 KB Output is correct
59 Correct 48 ms 15868 KB Output is correct
60 Correct 48 ms 15956 KB Output is correct