QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#665475#7781. Sheep Eat WolvesKIRITO1211WA 1ms3640kbC++232.3kb2024-10-22 13:14:512024-10-22 13:14:52

Judging History

你现在查看的是最新测评结果

  • [2024-10-22 13:14:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3640kb
  • [2024-10-22 13:14:51]
  • 提交

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});
    vis[x][y][0] = 1;
    int cnt = 0;
    while(!qq.empty()){
        auto &[xx, yy, st] = qq.front();
        qq.pop();
        cnt++;
        if(cnt >= 1e4){
            std::cout<<-1<<'\n';
            return;
        }
        //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);
                    if(!vis[i][j][1])
                        vis[i][j][1] = 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);
                    if(!vis[i][j][0])
                        vis[i][j][1] = 0,
                                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;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3640kb

input:

4 4 3 1

output:

-1

result:

wrong answer 1st numbers differ - expected: '3', found: '-1'