답안 #1002172

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1002172 2024-06-19T10:41:02 Z vjudge1 로봇 (APIO13_robots) C++17
10 / 100
4 ms 6492 KB
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back	
#define pob pop_back
#define int long long
#define int2 __int128_t
#define Shrek_Crush228 ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define F first
#define S second
#define sz size()
#define FOR( i, x, n, d ) for( int i = x; i <= n; i += d )
#define FORR( i, x, n, d ) for( int i = x; i >= n; i -= d )
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define no cout << "NO\n"
#define yes cout << "YES\n"
#define nep next_permutation
#define sigma signed
#define pii pair <int, int> 

using namespace std;

string alp = "abcdefghijklmnopqrstuvwxyz";
string ae = "aoeiuy";
string nums = "123456789";

const int N = 3e5 + 123;
const int inf = 1e18;
const int MOD = 1e9 + 7;
const int MOD1 = 998244353;

int a[N], b[N], c[N], d[N], l, r, n, k, m, w, cur, cnt, res, sum, sum1, x, y, ans, ans1, mx = -inf, mn = inf, ind, ind1, pref[N], suf[N];
string s, s1;

struct RT
{
	int sum, l, r, ind;	
};
int gcd( int a, int b )
{
	return ( b ? gcd( b, a % b ) : a );
}
int lcm( int a, int b )
{
	return a / gcd( a, b ) * b;
}
int bp( int a, int b, int m )
{
	if( !b ) return 1;
	if( b & 1 ) return bp( a, b - 1, m ) * a % m;
	
	int it = bp( a, b >> 1, m );
	return it * it % m;
}
struct po
{
	int v1, v2, v3;
};
char maze[505][505];
int used[505][505];
vector <pii> g[505][505];
int been[505][505][10];

pii to( int x, int y, int tp )
{
	if( been[x][y][tp] ) return {-inf, -inf};
	been[x][y][tp] = 1;
	
	if( tp == 1 )
	{
		if( maze[x][y - 1] == 'x' || y - 1 < 1 ) return { x, y };
		if( maze[x][y - 1] == 'A' ) return to( x, y - 1, 3 );
		if( maze[x][y - 1] == 'C' ) return to( x, y - 1, 4 );
		return to( x, y - 1, 1 );
	}
	if( tp == 2 )
	{
		if( maze[x][y + 1] == 'x' || y + 1 > m ) return { x, y };
		if( maze[x][y + 1] == 'A' ) return to( x, y + 1, 4 );
		if( maze[x][y + 1] == 'C' ) return to( x, y + 1, 3 );
		return to( x, y + 1, 2 );
	}
	if( tp == 3 )
	{
		if( maze[x - 1][y] == 'x' || x - 1 < 1 ) return { x, y };
		if( maze[x - 1][y] == 'A' ) return to( x - 1, y, 2 );
		if( maze[x - 1][y] == 'C' ) return to( x - 1, y, 1 );
		return to( x - 1, y, 3 );
	}
	if( tp == 4 )
	{
		if( maze[x + 1][y] == 'x' || x + 1 > n ) return { x, y };
		if( maze[x + 1][y] == 'A' ) return to( x + 1, y, 1 );
		if( maze[x + 1][y] == 'C' ) return to( x + 1, y, 2 );
		return to( x + 1, y, 4 );
	}
}
void get( int xn, int yn, int xst, int yst, int dist )
{
	if( used[xn][yn] <= dist ) return;
	used[xn][yn] = dist;
	
	if( xn == xst && yn == yst )
	{
		ans = min( ans, dist );
		return;
	}
	int xl, yl, xr, yr, xu, yu, xd, yd, okl = 0, okr = 0, oku = 0, okd = 0;
	
	tie( xl, yl ) = g[xn][yn][0];
	tie( xr, yr ) = g[xn][yn][1];
	tie( xu, yu ) = g[xn][yn][2];
	tie( xd, yd ) = g[xn][yn][3];
	
	if( xl + yl > 0 ) get( xl, yl, xst, yst, dist + 1 );
	if( xr + yr > 0 ) get( xr, yr, xst, yst, dist + 1 ); 
	if( xu + yu > 0 ) get( xu, yu, xst, yst, dist + 1 );
	if( xd + yd > 0 ) get( xd, yd, xst, yst, dist + 1 );
}
void clean()
{
	FOR( i, 0, n + 1, 1 )
	{
		FOR( j, 0, m + 1, 1 ) used[i][j] = inf;
	}
	FOR( ii, 0, n + 1, 1 )
	{
		FOR( jj, 0, m + 1, 1 )
		{
			FOR( tp, 0, 5, 1 )
			{
				been[ii][jj][tp] = 0;
			}
		}
	}
}
void solve()
{
	cin >> k >> m >> n;
	int x1, y1, x2, y2;	
	
	FOR( i, 1, n, 1 )
	{
		FOR( j, 1, m, 1 ) 
		{
			cin >> maze[i][j];
			if( maze[i][j] == '1' ) x1 = i, y1 = j;
			if( maze[i][j] == '2' ) x2 = i, y2 = j;
		}
	} clean();
	FOR( i, 1, n, 1 )
	{
		FOR( j, 1, m, 1 ) 
		{
			g[i][j].pb( to( i, j, 1 ) ); clean();
			g[i][j].pb( to( i, j, 2 ) ); clean();
			g[i][j].pb( to( i, j, 3 ) ); clean();
			g[i][j].pb( to( i, j, 4 ) ); clean();
		}
	} 
	ans = 1e9;
	pii L = to( x2, y2, 1 ); clean();
	pii R = to( x2, y2, 2 ); clean();
	pii U = to( x2, y2, 3 ); clean();
	pii D = to( x2, y2, 4 ); clean();
	
	if( L.F + L.S > 0 ) get( x1, y1, L.F, L.S, 1 ); clean();
	if( R.F + R.S > 0 ) get( x1, y1, R.F, R.S, 1 ); clean();
	if( U.F + U.S > 0 ) get( x1, y1, U.F, U.S, 1 );	clean();
	if( D.F + D.S > 0 ) get( x1, y1, D.F, D.S, 1 );	clean();
	get( x1, y1, x2, y2, 0 );
	
	//cout << U.F << ' ' << U.S << '\n';
	cout << ( ans == 1e9 ? -1 : ans );
}
sigma main() 
{
	//freopen("haircut.in", "r", stdin);
	//freopen("haircut.out", "w", stdout);
	
    Shrek_Crush228
    
    int test = 1;
    
    if( !test ) cin >> test;
	
	while( test -- )
	{
		solve();
	}
}
//// solved by KluydQ
/*

*/

Compilation message

robots.cpp: In function 'void get(long long int, long long int, long long int, long long int, long long int)':
robots.cpp:115:38: warning: unused variable 'okl' [-Wunused-variable]
  115 |  int xl, yl, xr, yr, xu, yu, xd, yd, okl = 0, okr = 0, oku = 0, okd = 0;
      |                                      ^~~
robots.cpp:115:47: warning: unused variable 'okr' [-Wunused-variable]
  115 |  int xl, yl, xr, yr, xu, yu, xd, yd, okl = 0, okr = 0, oku = 0, okd = 0;
      |                                               ^~~
robots.cpp:115:56: warning: unused variable 'oku' [-Wunused-variable]
  115 |  int xl, yl, xr, yr, xu, yu, xd, yd, okl = 0, okr = 0, oku = 0, okd = 0;
      |                                                        ^~~
robots.cpp:115:65: warning: unused variable 'okd' [-Wunused-variable]
  115 |  int xl, yl, xr, yr, xu, yu, xd, yd, okl = 0, okr = 0, oku = 0, okd = 0;
      |                                                                 ^~~
robots.cpp: In function 'void solve()':
robots.cpp:174:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  174 |  if( L.F + L.S > 0 ) get( x1, y1, L.F, L.S, 1 ); clean();
      |  ^~
robots.cpp:174:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  174 |  if( L.F + L.S > 0 ) get( x1, y1, L.F, L.S, 1 ); clean();
      |                                                  ^~~~~
robots.cpp:175:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  175 |  if( R.F + R.S > 0 ) get( x1, y1, R.F, R.S, 1 ); clean();
      |  ^~
robots.cpp:175:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  175 |  if( R.F + R.S > 0 ) get( x1, y1, R.F, R.S, 1 ); clean();
      |                                                  ^~~~~
robots.cpp:176:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  176 |  if( U.F + U.S > 0 ) get( x1, y1, U.F, U.S, 1 ); clean();
      |  ^~
robots.cpp:176:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  176 |  if( U.F + U.S > 0 ) get( x1, y1, U.F, U.S, 1 ); clean();
      |                                                  ^~~~~
robots.cpp:177:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  177 |  if( D.F + D.S > 0 ) get( x1, y1, D.F, D.S, 1 ); clean();
      |  ^~
robots.cpp:177:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  177 |  if( D.F + D.S > 0 ) get( x1, y1, D.F, D.S, 1 ); clean();
      |                                                  ^~~~~
robots.cpp: In function 'std::pair<long long int, long long int> to(long long int, long long int, long long int)':
robots.cpp:104:1: warning: control reaches end of non-void function [-Wreturn-type]
  104 | }
      | ^
robots.cpp: In function 'void solve()':
robots.cpp:178:5: warning: 'y2' may be used uninitialized in this function [-Wmaybe-uninitialized]
  178 |  get( x1, y1, x2, y2, 0 );
      |  ~~~^~~~~~~~~~~~~~~~~~~~~
robots.cpp:178:5: warning: 'x2' may be used uninitialized in this function [-Wmaybe-uninitialized]
robots.cpp:178:5: warning: 'y1' may be used uninitialized in this function [-Wmaybe-uninitialized]
robots.cpp:178:5: warning: 'x1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6472 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6472 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 3 ms 6488 KB Output is correct
7 Correct 2 ms 6468 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Incorrect 2 ms 6492 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6472 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 3 ms 6488 KB Output is correct
7 Correct 2 ms 6468 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Incorrect 2 ms 6492 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6472 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 3 ms 6488 KB Output is correct
7 Correct 2 ms 6468 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Incorrect 2 ms 6492 KB Output isn't correct
10 Halted 0 ms 0 KB -