답안 #521654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521654 2022-02-02T17:01:20 Z CaroLinda Navigation 2 (JOI21_navigation2) C++17
100 / 100
1008 ms 872 KB
#include "Anna.h"
#include <bits/stdc++.h>

#define mk make_pair

using namespace std ;


void Anna(int N, int K, vector<int> R, vector<int> C) {

	vector<bool> classes(9, false) ;
	int dx[9] = {0,0,1,-1,1,1,-1,-1, 0} , dy[9] = {1,-1,0,0, 1, -1, 1, -1, 0} ;

	for(int i = 0 ; i < K ; i++ ){
		int x = R[i]%3 ;
		int y = C[i]%3 ;
		int num = x*3 + y ;
		classes[num] = true ;
	}			

	vector<int> unused ;
	for(int i = 0 ; i < 9 && (int)unused.size() < 2; i++ )
		if(!classes[i] ) unused.push_back(i) ;

	vector<int> val(9,12) ;
	int lastVal = 0 ;

	auto getClass = [&](int a, int b) {
		a %= 3 ;
		a = (a+3)%3 ;
		b %= 3 ;
		b = (b+3)%3 ;

		return a*3 + b ;
	} ;

	vector<pair<int,int> > deltas = { mk(0,1) , mk(1,0) , mk(1,-1) , mk(1,1) } ;

	for(int i = 0 ; i < 2 ; i++ , swap(unused[0], unused[1] ) ) {
		bool ok = false ;

		int c = unused[1]/3 , d = unused[1]%3 ;

		for(auto e : deltas ) {
			int a = e.first+c ;
			int b = e.second+d ;
			if(getClass(a,b) == unused[0] ) ok = true ;			
      }

      if(ok) break ;
	}

	int a = unused[0]/3 , b = unused[0]%3 ;

	for(int i = 0 , q = 0 ; i < 8 ; i++ ){
		int na = a + dx[i] ;
		int nb = b + dy[i] ;
		if( getClass(na,nb) == unused[1] ) continue ;
		val[ getClass(na,nb) ] = q++ ;
	}	

	auto getDistance = [&](int a, int b, int p){
		int dx = abs(a-R[p]) ;
		int dy =abs(b-C[p] ) ;
		return dx+dy ;
	} ;

	for(int i = 0 ; i< N ; i++ ){
		for(int j= 0 ; j<N ; j++ ){

			if( getClass(i,j) == unused[0] || getClass(i,j) == unused[1] ){
				SetFlag(i,j,12) ;
				continue ;
			}

			if(val[ getClass(i,j) ] >= K ) { SetFlag(i,j,1) ; continue ; }

			int myParty = val[ getClass(i,j) ] ;
			int d = getDistance(i,j, myParty ) ;
			bool ok = false ;
			int idx = 1; 

			for(int g = 0 , ni , nj  ; g < 9 ; g++ ){
				ni = i+dx[g] ;
				nj = j+dy[g] ;

				if(getClass(ni,nj) == unused[0] || getClass(ni,nj) == unused[1] ) continue ;
				if( getDistance(ni,nj,myParty ) == 0 ){
					SetFlag(i,j,idx) ;
					ok = true ;
					break ;
				}
				idx++ ;
			}

			if(ok) continue ;

			if(C[myParty]-j >= 2 ) SetFlag(i,j,8) ;
			else if(j-C[myParty] >= 2 ) SetFlag(i,j,9) ;
			else if( R[myParty]-i >= 2 ) SetFlag(i,j,10) ;
			else SetFlag(i,j,11) ;

		}
	}


}
#include "Bruno.h"
#include <bits/stdc++.h>

#define mk make_pair
#define debug printf

using namespace std ;

std::vector<int> Bruno(int K, std::vector<int> value) {

	auto getClass = [&](int a, int b){
		a = a%3 ;
		a = (a+3)%3 ;
		b = b%3 ;
		b = (b+3)%3 ;
		return a*3 + b ;
	} ;


	int dx[9] = {0,0,1,-1,1,1,-1,-1, 0} , dy[9] = {1,-1,0,0, 1, -1, 1, -1, 0} ;

	vector<pair<int,int> > vec ;
	vector< vector<int> > grid(3, vector<int>(3) ) , party(3, vector<int>(3,-1) ) ;

	for(int i = 0 , a = 0 , b = 0 ; i < 9 ; i++ , b++ ){
		if(b == 3 ) a++ , b = 0 ;
		grid[a][b] = value[i] ;
		if(value[i] == 12 ) vec.push_back(make_pair(a,b) ) ;
	}
	
	vector<pair<int,int> > deltas = { mk(0,1) , mk(1,0) , mk(1,-1) , mk(1,1) } ;

	for(int i = 0 ; i < 2 ; i++ , swap(vec[0], vec[1] ) ){
		bool ok = false ;


		for(auto e : deltas ) {
			int x = vec[1].first+e.first ;
			int y = vec[1].second+e.second ;
			if(getClass(x,y) == getClass( vec[0].first, vec[0].second ) ) ok = true ;
      }

      if(ok) break ;
	}
   
	auto getDistance = [&](int a, int b, int c, int d){
		int dx = abs(a-c) ;
		int dy = abs(b-d) ;
		return dx + dy ;
	} ;

	auto getDirection = [&](int a, int b, int c, int d ){
		if( a == c && b == d ) return 4 ;		
		for(int i = 0 , na , nb ; i < 4 ; i++ ){
			na = a + dx[i] ;
			nb = b + dy[i] ;
			if(getDistance(na,nb,c,d) >= getDistance(a,b,c,d) ) continue ;
			return i ;
		}
	} ;

	int num = getClass(vec[0].first, vec[0].second) ;
	int x = num+1 ;

	vector<int> val(9,-1) ;

	for( int i = 0, q = 0 ; i< 8 ; i++ ){
		int na = vec[0].first+dx[i] ;
		int nb = vec[0].second + dy[i] ;
		if( getClass(na,nb) == getClass(vec[1].first, vec[1].second) ) continue ;

		val[ getClass(na,nb) ] = q++ ;
	}

/*	cout << vec[0].first <<" " << vec[0].second << " " << vec[1].first <<" " << vec[1].second << endl ;

	cout << "Printing grid" << endl ;
	for(int i = 0 ; i < 3 ; i++ , cout << endl )
		for(int j = 0 ; j < 3 ; j++ ) cout << grid[i][j] <<" " ; */

	for(int i = 0 ; i < 3 ; i++ )
		for(int j = 0 ; j< 3 ; j++ ) party[i][j] = val[ getClass(i,j) ] ;

	vector<int> ans(K,-1) ;
	vector<int> unused = { getClass(vec[0].first, vec[0].second), getClass(vec[1].first, vec[1].second) } ;

	for(int i = 0 ; i < 3 ; i++ )
		for(int j = 0 ; j < 3 ; j++ ){

			if( grid[i][j] == 12 || party[i][j] >= K ) {
				continue ;
			}

			if( grid[i][j] >= 8 ){

				int mov = grid[i][j]-8 ;
				ans[ party[i][j] ]=mov ;

				continue ;
			}			

			int idx =1  , A , B ;
			for(int g = 0 ; g < 9 ; g++ ){

				int code=getClass(dx[g]+i , dy[g]+j) ;

				if( code == unused[0] || code == unused[1] ) continue ;

				if( idx == grid[i][j] ){
					A = dx[g]+i ;
					B = dy[g] + j ;					
					break ;
				}

				idx++ ;
			}

			ans[ party[i][j] ]  = getDirection(1,1,A,B) ;

		}

	return ans ;

}

Compilation message

Anna.cpp: In function 'void Anna(int, int, std::vector<int>, std::vector<int>)':
Anna.cpp:79:8: warning: unused variable 'd' [-Wunused-variable]
   79 |    int d = getDistance(i,j, myParty ) ;
      |        ^
Anna.cpp:26:6: warning: unused variable 'lastVal' [-Wunused-variable]
   26 |  int lastVal = 0 ;
      |      ^~~~~~~

Bruno.cpp: In function 'std::vector<int> Bruno(int, std::vector<int>)':
Bruno.cpp:63:6: warning: unused variable 'x' [-Wunused-variable]
   63 |  int x = num+1 ;
      |      ^
Bruno.cpp: In lambda function:
Bruno.cpp:60:2: warning: control reaches end of non-void function [-Wreturn-type]
   60 |  } ;
      |  ^
Bruno.cpp: In function 'std::vector<int> Bruno(int, std::vector<int>)':
Bruno.cpp:53:19: warning: 'B' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |   if( a == c && b == d ) return 4 ;
      |                 ~~^~~~
Bruno.cpp:53:9: warning: 'A' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |   if( a == c && b == d ) return 4 ;
      |       ~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 392 KB Output is correct
2 Correct 10 ms 476 KB Output is correct
3 Correct 11 ms 392 KB Output is correct
4 Correct 13 ms 480 KB Output is correct
5 Correct 10 ms 520 KB Output is correct
6 Correct 17 ms 392 KB Output is correct
7 Correct 13 ms 392 KB Output is correct
8 Correct 12 ms 392 KB Output is correct
9 Correct 13 ms 392 KB Output is correct
10 Correct 10 ms 556 KB Output is correct
11 Correct 14 ms 460 KB Output is correct
12 Correct 13 ms 392 KB Output is correct
13 Correct 13 ms 404 KB Output is correct
14 Correct 13 ms 392 KB Output is correct
15 Correct 9 ms 476 KB Output is correct
16 Correct 15 ms 472 KB Output is correct
17 Correct 13 ms 392 KB Output is correct
18 Correct 14 ms 392 KB Output is correct
19 Correct 12 ms 480 KB Output is correct
20 Correct 16 ms 392 KB Output is correct
21 Correct 13 ms 472 KB Output is correct
22 Correct 17 ms 392 KB Output is correct
23 Correct 13 ms 392 KB Output is correct
24 Correct 15 ms 480 KB Output is correct
25 Correct 12 ms 392 KB Output is correct
26 Correct 14 ms 392 KB Output is correct
27 Correct 17 ms 392 KB Output is correct
28 Correct 13 ms 392 KB Output is correct
29 Correct 14 ms 392 KB Output is correct
30 Correct 13 ms 392 KB Output is correct
31 Correct 12 ms 392 KB Output is correct
32 Correct 13 ms 472 KB Output is correct
33 Correct 9 ms 472 KB Output is correct
34 Correct 12 ms 392 KB Output is correct
35 Correct 13 ms 392 KB Output is correct
36 Correct 13 ms 392 KB Output is correct
37 Correct 18 ms 392 KB Output is correct
38 Correct 13 ms 392 KB Output is correct
39 Correct 14 ms 392 KB Output is correct
40 Correct 14 ms 392 KB Output is correct
41 Correct 17 ms 392 KB Output is correct
42 Correct 17 ms 392 KB Output is correct
43 Correct 20 ms 392 KB Output is correct
44 Correct 14 ms 392 KB Output is correct
45 Correct 18 ms 392 KB Output is correct
46 Correct 18 ms 392 KB Output is correct
47 Correct 13 ms 468 KB Output is correct
48 Correct 15 ms 392 KB Output is correct
49 Correct 15 ms 392 KB Output is correct
50 Correct 11 ms 472 KB Output is correct
51 Correct 12 ms 472 KB Output is correct
52 Correct 18 ms 392 KB Output is correct
53 Correct 13 ms 392 KB Output is correct
54 Correct 15 ms 392 KB Output is correct
55 Correct 18 ms 472 KB Output is correct
56 Correct 18 ms 392 KB Output is correct
57 Correct 20 ms 400 KB Output is correct
58 Correct 17 ms 392 KB Output is correct
59 Correct 21 ms 392 KB Output is correct
60 Correct 26 ms 392 KB Output is correct
61 Correct 18 ms 392 KB Output is correct
62 Correct 18 ms 392 KB Output is correct
63 Correct 23 ms 392 KB Output is correct
64 Correct 20 ms 480 KB Output is correct
65 Correct 18 ms 392 KB Output is correct
66 Correct 18 ms 472 KB Output is correct
67 Correct 19 ms 472 KB Output is correct
68 Correct 24 ms 392 KB Output is correct
69 Correct 17 ms 392 KB Output is correct
70 Correct 17 ms 392 KB Output is correct
71 Correct 17 ms 392 KB Output is correct
72 Correct 22 ms 392 KB Output is correct
73 Correct 19 ms 392 KB Output is correct
74 Correct 16 ms 604 KB Output is correct
75 Correct 23 ms 392 KB Output is correct
76 Correct 17 ms 392 KB Output is correct
77 Correct 19 ms 412 KB Output is correct
78 Correct 21 ms 392 KB Output is correct
79 Correct 19 ms 392 KB Output is correct
80 Correct 19 ms 392 KB Output is correct
81 Correct 15 ms 472 KB Output is correct
82 Correct 16 ms 472 KB Output is correct
83 Correct 20 ms 392 KB Output is correct
84 Correct 19 ms 392 KB Output is correct
85 Correct 15 ms 392 KB Output is correct
86 Correct 18 ms 392 KB Output is correct
87 Correct 18 ms 392 KB Output is correct
88 Correct 25 ms 392 KB Output is correct
89 Correct 20 ms 392 KB Output is correct
90 Correct 23 ms 392 KB Output is correct
91 Correct 17 ms 392 KB Output is correct
92 Correct 21 ms 392 KB Output is correct
93 Correct 18 ms 392 KB Output is correct
94 Correct 16 ms 472 KB Output is correct
95 Correct 19 ms 392 KB Output is correct
96 Correct 17 ms 392 KB Output is correct
97 Correct 17 ms 392 KB Output is correct
98 Correct 19 ms 392 KB Output is correct
99 Correct 18 ms 392 KB Output is correct
100 Correct 18 ms 392 KB Output is correct
101 Correct 17 ms 476 KB Output is correct
102 Correct 18 ms 392 KB Output is correct
103 Correct 20 ms 392 KB Output is correct
104 Correct 13 ms 392 KB Output is correct
105 Correct 23 ms 392 KB Output is correct
106 Correct 19 ms 392 KB Output is correct
107 Correct 19 ms 392 KB Output is correct
108 Correct 18 ms 392 KB Output is correct
109 Correct 27 ms 392 KB Output is correct
110 Correct 19 ms 392 KB Output is correct
111 Correct 17 ms 392 KB Output is correct
112 Correct 14 ms 392 KB Output is correct
113 Correct 20 ms 392 KB Output is correct
114 Correct 17 ms 392 KB Output is correct
115 Correct 20 ms 472 KB Output is correct
116 Correct 20 ms 392 KB Output is correct
117 Correct 18 ms 392 KB Output is correct
118 Correct 16 ms 392 KB Output is correct
119 Correct 16 ms 392 KB Output is correct
120 Correct 737 ms 576 KB Output is correct
121 Correct 770 ms 772 KB Output is correct
122 Correct 769 ms 708 KB Output is correct
123 Correct 728 ms 636 KB Output is correct
124 Correct 748 ms 712 KB Output is correct
125 Correct 797 ms 712 KB Output is correct
126 Correct 769 ms 788 KB Output is correct
127 Correct 759 ms 572 KB Output is correct
128 Correct 748 ms 860 KB Output is correct
129 Correct 756 ms 688 KB Output is correct
130 Correct 778 ms 732 KB Output is correct
131 Correct 791 ms 692 KB Output is correct
132 Correct 763 ms 692 KB Output is correct
133 Correct 734 ms 620 KB Output is correct
134 Correct 790 ms 600 KB Output is correct
135 Correct 765 ms 704 KB Output is correct
136 Correct 780 ms 712 KB Output is correct
137 Correct 786 ms 668 KB Output is correct
138 Correct 859 ms 628 KB Output is correct
139 Correct 782 ms 648 KB Output is correct
140 Correct 747 ms 664 KB Output is correct
141 Correct 845 ms 640 KB Output is correct
142 Correct 780 ms 768 KB Output is correct
143 Correct 730 ms 800 KB Output is correct
144 Correct 733 ms 692 KB Output is correct
145 Correct 811 ms 552 KB Output is correct
146 Correct 765 ms 692 KB Output is correct
147 Correct 739 ms 720 KB Output is correct
148 Correct 770 ms 652 KB Output is correct
149 Correct 761 ms 588 KB Output is correct
150 Correct 751 ms 624 KB Output is correct
151 Correct 774 ms 616 KB Output is correct
152 Correct 764 ms 604 KB Output is correct
153 Correct 1008 ms 584 KB Output is correct
154 Correct 744 ms 580 KB Output is correct
155 Correct 739 ms 648 KB Output is correct
156 Correct 793 ms 708 KB Output is correct
157 Correct 737 ms 724 KB Output is correct
158 Correct 794 ms 688 KB Output is correct
159 Correct 755 ms 736 KB Output is correct
160 Correct 727 ms 540 KB Output is correct
161 Correct 735 ms 584 KB Output is correct
162 Correct 714 ms 708 KB Output is correct
163 Correct 722 ms 716 KB Output is correct
164 Correct 732 ms 556 KB Output is correct
165 Correct 704 ms 812 KB Output is correct
166 Correct 741 ms 584 KB Output is correct
167 Correct 746 ms 532 KB Output is correct
168 Correct 694 ms 632 KB Output is correct
169 Correct 748 ms 776 KB Output is correct
170 Correct 751 ms 672 KB Output is correct
171 Correct 702 ms 640 KB Output is correct
172 Correct 731 ms 652 KB Output is correct
173 Correct 748 ms 728 KB Output is correct
174 Correct 782 ms 848 KB Output is correct
175 Correct 773 ms 676 KB Output is correct
176 Correct 717 ms 588 KB Output is correct
177 Correct 811 ms 688 KB Output is correct
178 Correct 793 ms 656 KB Output is correct
179 Correct 732 ms 584 KB Output is correct
180 Correct 776 ms 784 KB Output is correct
181 Correct 712 ms 692 KB Output is correct
182 Correct 732 ms 592 KB Output is correct
183 Correct 738 ms 500 KB Output is correct
184 Correct 740 ms 688 KB Output is correct
185 Correct 752 ms 716 KB Output is correct
186 Correct 709 ms 716 KB Output is correct
187 Correct 777 ms 612 KB Output is correct
188 Correct 717 ms 536 KB Output is correct
189 Correct 712 ms 600 KB Output is correct
190 Correct 702 ms 632 KB Output is correct
191 Correct 749 ms 572 KB Output is correct
192 Correct 750 ms 564 KB Output is correct
193 Correct 737 ms 648 KB Output is correct
194 Correct 753 ms 488 KB Output is correct
195 Correct 827 ms 684 KB Output is correct
196 Correct 783 ms 664 KB Output is correct
197 Correct 712 ms 688 KB Output is correct
198 Correct 734 ms 872 KB Output is correct
199 Correct 731 ms 668 KB Output is correct
200 Correct 729 ms 648 KB Output is correct
201 Correct 761 ms 720 KB Output is correct
202 Correct 734 ms 780 KB Output is correct
203 Correct 792 ms 664 KB Output is correct
204 Correct 782 ms 692 KB Output is correct
205 Correct 850 ms 672 KB Output is correct
206 Correct 709 ms 796 KB Output is correct
207 Correct 726 ms 668 KB Output is correct
208 Correct 769 ms 672 KB Output is correct
209 Correct 729 ms 640 KB Output is correct
210 Correct 536 ms 800 KB Output is correct
211 Correct 545 ms 832 KB Output is correct
212 Correct 562 ms 656 KB Output is correct
213 Correct 592 ms 716 KB Output is correct
214 Correct 608 ms 596 KB Output is correct
215 Correct 558 ms 780 KB Output is correct
216 Correct 564 ms 684 KB Output is correct
217 Correct 599 ms 664 KB Output is correct
218 Correct 592 ms 680 KB Output is correct
219 Correct 567 ms 608 KB Output is correct
220 Correct 564 ms 672 KB Output is correct
221 Correct 564 ms 616 KB Output is correct
222 Correct 547 ms 548 KB Output is correct
223 Correct 562 ms 568 KB Output is correct
224 Correct 576 ms 664 KB Output is correct
225 Correct 601 ms 636 KB Output is correct
226 Correct 572 ms 672 KB Output is correct