Submission #413556

# Submission time Handle Problem Language Result Execution time Memory
413556 2021-05-28T22:25:04 Z nemethm Patkice (COCI20_patkice) C++17
0 / 50
1000 ms 204 KB
#include <iostream>
#include <list>
#include <algorithm>
#include <queue>
#include <vector>
#include <limits>
#include <set>
#include <numeric>
#include <string>
#include <assert.h>
#include <map>
#include <cmath>
#include <stack>
#include <cstring>
#pragma warning(disable : 4996)
using namespace std;
using ll = long long int;
const ll inf = 1e10;
const ll mod = 998244353;
void setIO(string s) {
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

char t[100][100];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	pair<int, int> start;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			cin >> t[i][j];
			if (t[i][j] == 'o') start = { i,j };
		}
	}
	pair<char, int> out = { -1,numeric_limits<int>::max() };
	char c[4] = { 'S', 'N', 'E', 'W' };
	pair<int, int> dir[4] = { {1,0},{-1,0}, {0,1}, {0,-1} };
	for (int i = 0; i < 4; ++i) {
		pair<int, int> p = { start.first + dir[i].first, start.second + dir[i].second };
		int l = 1;
		while (t[p.first][p.second] != '.' && t[p.first][p.second] != 'x') {
			switch (t[p.first][p.second])
			{
			case '>':
				++p.second;
				break;
			case '<':
				--p.second;
				break;
			case '^':
				--p.first;
				break;
			case 'v':
				++p.first;
				break;
			default:
				break;
			}
			++l;
		}
		if (t[p.first][p.second] == 'x') {
			if (l == out.second && c[i] < out.first) out.first = c[i];
			if (l < out.second) out = { c[i], l };
		}
	}
	if (out.first == -1)
		cout << ":(" << endl;
	else {
		cout << ":)\n" << out.first << endl;
	}
	return 0;
}

Compilation message

patkice.cpp:15: warning: ignoring '#pragma warning ' [-Wunknown-pragmas]
   15 | #pragma warning(disable : 4996)
      | 
patkice.cpp: In function 'void setIO(std::string)':
patkice.cpp:21:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |  freopen((s + ".in").c_str(), "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
patkice.cpp:22:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |  freopen((s + ".out").c_str(), "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -