답안 #941720

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
941720 2024-03-09T10:55:15 Z RavenHead Mecho (IOI09_mecho) C++17
13 / 100
99 ms 12056 KB
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define EB emplace_back
#define all(x) std::begin(x), std::end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(long long i = a; i < (b); ++i)
#define endl '\n'
#define debarr(a, n) cerr << #a << " : ";for(int i = 0; i < n; i++) cerr << a[i] << " "; cerr << endl;
#define debmat(mat, row, col) cerr << #mat << " :\n";for(int i = 0; i < row; i++) {for(int j = 0; j < col; j++) cerr << mat[i][j] << " ";cerr << endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

typedef long long lli;
typedef pair<lli, lli> ii;    typedef vector<lli> vi;
typedef vector<ii> vii;       typedef vector<vi> graph;
bool ckmax(auto &a, auto const& b) {return b > a ? a = b, 1 : 0;}
bool ckmin(auto &a, auto const& b) {return b < a ? a = b, 1 : 0;}

int const MOD = 1000000007;

void pre() {

}

void solve() {
	lli n, s;
	cin >> n >> s;
	vector<string> arr(n);
	rep(i, 0, n) {
		cin >> arr[i];
	}
	ii mecho, home;
	rep(i, 0, n)rep(j, 0, n) {
		if (arr[i][j] == 'M') {
			mecho = {i, j};
		}
		else if (arr[i][j] == 'D') {
			home = {i, j};
		}
	}

	// checks function
	auto checks = [&](lli xx, lli yy)->bool{
		if (xx >= 0 && xx < n && yy >= 0 && yy < n && (arr[xx][yy] == 'G' || arr[xx][yy] == 'D'))return true;
		return false;
	};

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

	graph dis(n, vi(n, 1e9));
	queue<ii> q;
	rep(i, 0, n)rep(j, 0, n)if (arr[i][j] == 'H') {
		q.push({i, j});
		dis[i][j] = 0;
	}
	while (!q.empty()) {
		auto nn = q.front(); q.pop();
		rep(dir, 0, 4) {
			lli xx = nn.F + dx[dir];
			lli yy = nn.S + dy[dir];
			if (checks(xx, yy)) {
				if (dis[xx][yy] > dis[nn.F][nn.S] + 1) {
					dis[xx][yy] = dis[nn.F][nn.S] + 1;
					q.push({xx, yy});
				}
			}
		}
	}

	// check function
	auto check = [&](lli mid)->bool{
		graph d(n, vi(n, 1e9));
		d[mecho.F][mecho.S] = 0;
		q.push(mecho);
		while (!q.empty()) {
			auto nn = q.front(); q.pop();
			rep(dir, 0, 4) {
				lli xx = nn.F + dx[dir];
				lli yy = nn.S + dy[dir];
				if (xx >= 0 && xx < n && yy >= 0 && yy < n && (arr[xx][yy] == 'G' || arr[xx][yy] == 'D')) {
					if (d[xx][yy] > d[nn.F][nn.S] + 1) {
						lli val = d[nn.F][nn.S] + 1;
						if (dis[xx][yy] >= mid + (val + s - 1) / s) {
							d[xx][yy] = val;
							q.push({xx, yy});
						}
					}
				}
			}
		}
		return mid + (d[home.F][home.S] + s - 1) / s < dis[home.F][home.S];
	};

	lli low = 0;
	lli high = 10;
	lli ans = -1;
	while (low <= high) {
		lli mid = (high + low) / 2;
		if (check(mid)) {
			ans = mid;
			low = mid + 1;
		} else high = mid - 1;
	}
	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	pre();
	int T = 1;
	while (T--)
		solve();
	return 0;
}

Compilation message

mecho.cpp:27:12: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   27 | bool ckmax(auto &a, auto const& b) {return b > a ? a = b, 1 : 0;}
      |            ^~~~
mecho.cpp:27:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   27 | bool ckmax(auto &a, auto const& b) {return b > a ? a = b, 1 : 0;}
      |                     ^~~~
mecho.cpp:28:12: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   28 | bool ckmin(auto &a, auto const& b) {return b < a ? a = b, 1 : 0;}
      |            ^~~~
mecho.cpp:28:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   28 | bool ckmin(auto &a, auto const& b) {return b < a ? a = b, 1 : 0;}
      |                     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Correct 0 ms 456 KB Output is correct
6 Incorrect 1 ms 344 KB Output isn't correct
7 Incorrect 58 ms 11316 KB Output isn't 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 1 ms 344 KB Output is correct
12 Incorrect 0 ms 348 KB Output isn't correct
13 Incorrect 1 ms 348 KB Output isn't correct
14 Correct 1 ms 348 KB Output is correct
15 Incorrect 0 ms 348 KB Output isn't correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Incorrect 0 ms 348 KB Output isn't correct
18 Incorrect 0 ms 348 KB Output isn't correct
19 Incorrect 0 ms 456 KB Output isn't correct
20 Incorrect 1 ms 348 KB Output isn't correct
21 Incorrect 0 ms 348 KB Output isn't correct
22 Incorrect 1 ms 344 KB Output isn't correct
23 Incorrect 1 ms 348 KB Output isn't correct
24 Incorrect 0 ms 452 KB Output isn't correct
25 Incorrect 1 ms 348 KB Output isn't correct
26 Incorrect 1 ms 456 KB Output isn't correct
27 Incorrect 1 ms 348 KB Output isn't correct
28 Incorrect 1 ms 348 KB Output isn't correct
29 Incorrect 1 ms 348 KB Output isn't correct
30 Incorrect 1 ms 348 KB Output isn't correct
31 Incorrect 1 ms 348 KB Output isn't correct
32 Incorrect 1 ms 344 KB Output isn't correct
33 Incorrect 6 ms 2576 KB Output isn't correct
34 Incorrect 8 ms 2596 KB Output isn't correct
35 Correct 10 ms 2568 KB Output is correct
36 Incorrect 7 ms 3188 KB Output isn't correct
37 Incorrect 10 ms 3272 KB Output isn't correct
38 Correct 15 ms 3188 KB Output is correct
39 Incorrect 10 ms 4032 KB Output isn't correct
40 Incorrect 12 ms 4028 KB Output isn't correct
41 Correct 16 ms 4184 KB Output is correct
42 Incorrect 12 ms 4844 KB Output isn't correct
43 Incorrect 16 ms 4840 KB Output isn't correct
44 Correct 27 ms 4864 KB Output is correct
45 Incorrect 18 ms 5776 KB Output isn't correct
46 Incorrect 17 ms 5768 KB Output isn't correct
47 Correct 31 ms 5812 KB Output is correct
48 Incorrect 23 ms 6804 KB Output isn't correct
49 Incorrect 20 ms 6744 KB Output isn't correct
50 Correct 54 ms 6784 KB Output is correct
51 Incorrect 20 ms 7892 KB Output isn't correct
52 Incorrect 34 ms 7844 KB Output isn't correct
53 Correct 42 ms 7920 KB Output is correct
54 Incorrect 24 ms 8900 KB Output isn't correct
55 Incorrect 31 ms 9048 KB Output isn't correct
56 Correct 68 ms 9048 KB Output is correct
57 Incorrect 29 ms 10236 KB Output isn't correct
58 Incorrect 38 ms 10296 KB Output isn't correct
59 Correct 70 ms 10300 KB Output is correct
60 Incorrect 30 ms 11632 KB Output isn't correct
61 Incorrect 45 ms 11636 KB Output isn't correct
62 Correct 96 ms 11620 KB Output is correct
63 Correct 66 ms 11628 KB Output is correct
64 Incorrect 98 ms 11596 KB Output isn't correct
65 Incorrect 94 ms 11672 KB Output isn't correct
66 Incorrect 85 ms 11564 KB Output isn't correct
67 Correct 59 ms 11588 KB Output is correct
68 Correct 49 ms 11676 KB Output is correct
69 Incorrect 46 ms 11672 KB Output isn't correct
70 Incorrect 44 ms 11548 KB Output isn't correct
71 Correct 40 ms 11656 KB Output is correct
72 Incorrect 51 ms 11608 KB Output isn't correct
73 Incorrect 57 ms 11700 KB Output isn't correct
74 Incorrect 60 ms 11688 KB Output isn't correct
75 Incorrect 57 ms 11688 KB Output isn't correct
76 Incorrect 61 ms 11592 KB Output isn't correct
77 Incorrect 49 ms 11600 KB Output isn't correct
78 Correct 59 ms 11796 KB Output is correct
79 Incorrect 64 ms 11624 KB Output isn't correct
80 Incorrect 55 ms 11632 KB Output isn't correct
81 Incorrect 51 ms 11480 KB Output isn't correct
82 Incorrect 57 ms 11648 KB Output isn't correct
83 Correct 63 ms 11684 KB Output is correct
84 Incorrect 72 ms 11520 KB Output isn't correct
85 Incorrect 61 ms 11664 KB Output isn't correct
86 Incorrect 70 ms 11684 KB Output isn't correct
87 Incorrect 69 ms 11720 KB Output isn't correct
88 Correct 51 ms 11628 KB Output is correct
89 Incorrect 99 ms 12056 KB Output isn't correct
90 Incorrect 70 ms 11668 KB Output isn't correct
91 Incorrect 50 ms 11600 KB Output isn't correct
92 Incorrect 51 ms 11672 KB Output isn't correct