QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#590#280505#7781. Sheep Eat Wolvesucup-team3175ucup-team1303Failed.2024-04-10 16:54:042024-04-10 16:54:05

Details

Extra Test:

Invalid Input

input:

psda mine

output:


result:

FAIL Expected integer, but "psda" found (stdin, line 1)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#280505#7781. Sheep Eat Wolvesucup-team1303#AC ✓39ms3956kbC++201.6kb2023-12-09 16:32:332024-10-14 07:46:31

answer

// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T& x, T y) {x = max(x, y);}
template <typename T> inline void chkmin(T& x, T y) {x = min(x, y);}
template <typename T> inline void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
const int N = 110;
int f[N][N][2];
int x, y, p, q;
signed main() {
	ms(f, 0x3f);
	cin >> x >> y >> p >> q;
	f[x][y][0] = 0;
	queue <pair <pair <int, int>, int>> q;
	q.emplace(make_pair(x, y), 0);
	while (q.size()) {
		int x = q.front().first.first, y = q.front().first.second, z = q.front().second; q.pop();
		// debug << x << " " << y << " " << z << " " << f[x][y][z] << endl;
		F(i, 0, min(x, p))
			F(j, 0, min(y, p - i)) {
				if (x - i && y - j > x - i + ::q) continue;
				if (f[x][y][z] + 1 < f[::x - (x - i)][::y - (y - j)][z ^ 1]) {
					f[::x - (x - i)][::y - (y - j)][z ^ 1] = f[x][y][z] + 1;
					q.emplace(make_pair(::x - (x - i), ::y - (y - j)), z ^ 1);
				}
			}
	}
	int minn = 1e9 + 5;
	F(i, 0, y) chkmin(minn, f[x][i][1]);
	if (minn < 1e9) cout << minn;
	else cout << -1;
	return 0;
}
/* why?
*/