Submission #851342

# Submission time Handle Problem Language Result Execution time Memory
851342 2023-09-19T16:26:56 Z vjudge1 Patkice (COCI20_patkice) C++
30 / 50
1 ms 460 KB
#include <bits/stdc++.h>
using namespace std;
#define sp << " " << 
//#define int long long
#define vi vector<int>
#define pb push_back
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
const int N = 2e5+1;



void solve() {
	int n,m;
	cin >> n >> m;
	char grid[n+1][m+1];
	int px,py;
	F(i,n) {
		string s;
		cin >> s;
		F(j,m) {
			grid[i][j] = s[j-1];
			if (grid[i][j] == 'o') px = i,py = j;
		}
	}
	vector<char> dirs = {'E','W','N','S'};
	vi dx = {0,0,-1,1};
	vi dy = {1,-1,0,0};
	int steps = 1e9;
	string ans;
	char ans2;
	for (int i=0;i<4;i++) {
		int x = px+dx[i];
		int y = py+dy[i];
		if (!(x <= n && x >= 1 && y <=m &&  y >= 1)) continue;
		int haha = 0;
		while (grid[x][y] != '.') {
			haha++;
			if (grid[x][y] == '>') y++;
			else if (grid[x][y] == '<') y--;
			else if (grid[x][y] == '^') x--;
			else if (grid[x][y] == 'v') x++;
			else break;
		}
		if (grid[x][y] == 'x') {
			if (haha < steps){
				steps = haha;
				ans = ":)\n";
				ans2 = dirs[i];
			}
		}
	}
	if (ans[1] == ')') cout << ans << ans2 << endl;
	else cout << ":(\n";
}    
 
 
 
                                
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}
 
 
 

Compilation message

patkice.cpp: In function 'void solve()':
patkice.cpp:30:7: warning: 'ans2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   30 |  char ans2;
      |       ^~~~
patkice.cpp:32:18: warning: 'px' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |   int x = px+dx[i];
      |                  ^
patkice.cpp:33:18: warning: 'py' may be used uninitialized in this function [-Wmaybe-uninitialized]
   33 |   int y = py+dy[i];
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 412 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 460 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Incorrect 0 ms 456 KB Output isn't correct
18 Halted 0 ms 0 KB -