QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#682847 | #7781. Sheep Eat Wolves | guohaonan | WA | 0ms | 4000kb | C++14 | 2.3kb | 2024-10-27 17:33:33 | 2024-10-27 17:33:34 |
Judging History
answer
#include <bits/stdc++.h>
#define i32 int
#define i64 long long
#define pll pair<i64, i64>
const int N = 110;
using namespace std;
i64 dp[2][N][N];//
int x, y, p, q;
int main(){
memset(dp, 0x3f, sizeof dp);
cin >> x >> y >> p >> q;
dp[0][x][y] = 0;
queue<array<int, 3>> qq;
qq.push({0, x, y});
i64 ans = 1e15;
while (!qq.empty()){
auto [o, xx, yy] = qq.front(); qq.pop();
// cout << o << ' ' << xx << ' ' << yy << "------------" << endl;
if (o == 0){
for (int i = 0; i <= xx; i ++){
for (int j = 0; j <= yy; j ++){
// cout << i << ' ' << i + j << ' ' << yy - j + q << ' ' << xx - i << ' ' << dp[1][xx - i][yy - j] << endl;
// if (xx == 3 && yy == 4 && i == 3 && j == 0) cout << i << ' ' << j << "djwodwo" << endl;
if (i + j > p) continue;
if (yy - j + q > (xx - i) && (xx - i) != 0) continue;
if (dp[1][xx - i][yy - j] != 0x3f3f3f3f3f3f3f3f) continue;
// cout << 1 << ' ' << xx - i << ' ' << yy - j << endl;
qq.push({1, (xx - i), (yy - j)});
dp[1][xx - i][yy - j] = dp[0][xx][yy] + 1;
if (xx - i == 0) {
cout << dp[1][xx - i][yy - j] << endl;
return 0;
// ans = min(ans, dp[1][xx - i][yy - j]);
}
}
}
}else{
for (int i = 0; i <= x-xx; i ++){
for (int j = 0; j <= y-yy; j ++){
if (i + j > p) continue;
if (y - yy - j + q > (x - xx - i) && (x - xx - i) != 0) continue;
// if (j == 0) cout << "FUCK YOU !!!\n";
if (dp[0][xx + i][yy + j] != 0x3f3f3f3f3f3f3f3f) continue;
// cout << 0 << ' ' << xx + i << ' ' << yy + j << endl;
qq.push({0, xx + i, (yy + j)});
dp[0][xx + i][yy + j] = dp[1][xx][yy] + 1;
}
}
}
}
if (ans != 1e15) cout << ans << endl;
else cout << "-1\n";
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3748kb
input:
4 4 3 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
3 5 2 0
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 4000kb
input:
2 5 1 1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
1 1 1 0
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3788kb
input:
3 3 1 1
output:
-1
result:
wrong answer 1st numbers differ - expected: '7', found: '-1'