QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#665477 | #7781. Sheep Eat Wolves | KIRITO1211 | RE | 1ms | 3824kb | C++23 | 2.1kb | 2024-10-22 13:17:51 | 2024-10-22 13:17:52 |
Judging History
answer
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define int long long
using ll = long long;
using i64 = long long;
const int mod = 1e9 + 7;
// #define DEBUG
// 线段树合并信息
using viii = std::vector<std::vector<std::vector<int> > >;
using vii = std::vector<std::vector<int> >;
void solve() {
int x,y,p,q;std::cin>>x>>y>>p>>q;
viii dp(x + 2, vii(y + 2, std::vector<int>(2, 1e18)));
dp[x][y][0] = 0;
viii vis(x + 2, vii(y + 2, std::vector<int>(2, 0)));
std::queue<std::tuple<int, int, int> > qq;
qq.push({x, y, 0});
int cnt = 0;
while(!qq.empty()){
auto &[xx, yy, st] = qq.front();
qq.pop();
cnt++;
if(cnt >= 1e4)break;
if(vis[xx][yy][st]) continue;
vis[xx][yy][st] = 1;
//std::cerr<<xx<<yy<<st<<'\n';
for(int i = 0;i <= x;i++){
for(int j = 0;j <= y;j++){
if(st == 0){
if(i > xx || j > yy) continue;
if((j > i + q && i != 0)||( xx - i + yy - j > p))continue;
dp[i][j][1] = std::min(dp[i][j][1], dp[xx][yy][st] + 1);
qq.push({i, j, 1});
}
else{
if(i < xx || j < yy) continue;
if((y - j> x - i + q && x - i != 0)|| (i - xx + j - yy > p))continue;
dp[i][j][0] = std::min(dp[i][j][0], dp[xx][yy][st] + 1);
qq.push({i, j, 0});
}
}
}
}
int ans = 1e18;
for(int j = 0;j <= y;j++){
ans = std::min(ans, dp[0][j][0]);
ans = std::min(ans, dp[0][j][1]);
}
std::cout<<(ans == 1e18 ? -1 : ans)<<'\n';
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout<<std::fixed<<std::setprecision(10);
int t = 1;
// int res = 0;
// for(int i = 1;i <= 1145;i++) res |= i;
// std::cerr<<res<<'\n';
//std::cin>>t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
4 4 3 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
3 5 2 0
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
2 5 1 1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
1 1 1 0
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
3 3 1 1
output:
7
result:
ok 1 number(s): "7"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
3 3 2 1
output:
3
result:
ok 1 number(s): "3"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
10 9 1 10
output:
19
result:
ok 1 number(s): "19"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
15 20 2 5
output:
27
result:
ok 1 number(s): "27"
Test #9:
score: -100
Runtime Error
input:
18 40 16 7