QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#280099#7781. Sheep Eat Wolvesucup-team088#AC ✓99ms12304kbC++178.0kb2023-12-09 13:51:472024-10-14 07:46:21

Judging History

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

  • [2024-10-14 07:46:21]
  • 管理员手动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:99ms
  • 内存:12304kb
  • [2024-09-05 08:34:25]
  • hack成功,自动添加数据
  • (/hack/803)
  • [2024-09-05 08:23:36]
  • hack成功,自动添加数据
  • (/hack/802)
  • [2023-12-09 13:51:47]
  • 评测
  • 测评结果:100
  • 用时:111ms
  • 内存:12292kb
  • [2023-12-09 13:51:47]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#include<chrono>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
//ll mod = 1;
constexpr ll mod = 998244353;
//constexpr ll mod = 1000000007;
const int mod17 = 1000000007;
const ll INF = (ll)mod17 * mod17;
typedef pair<int, int>P;

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;

using ld = double;
typedef pair<ld, ld> LDP;
const ld eps = 1e-10;
const ld pi = acosl(-1.0);

template<typename T>
void chmin(T& a, T b) {
    a = min(a, b);
}
template<typename T>
void chmax(T& a, T b) {
    a = max(a, b);
}
template<typename T>
vector<T> vmerge(vector<T>& a, vector<T>& b) {
    vector<T> res;
    int ida = 0, idb = 0;
    while (ida < a.size() || idb < b.size()) {
        if (idb == b.size()) {
            res.push_back(a[ida]); ida++;
        }
        else if (ida == a.size()) {
            res.push_back(b[idb]); idb++;
        }
        else {
            if (a[ida] < b[idb]) {
                res.push_back(a[ida]); ida++;
            }
            else {
                res.push_back(b[idb]); idb++;
            }
        }
    }
    return res;
}
template<typename T>
void cinarray(vector<T>& v) {
    rep(i, v.size())cin >> v[i];
}
template<typename T>
void coutarray(vector<T>& v) {
    rep(i, v.size()) {
        if (i > 0)cout << " "; cout << v[i];
    }
    cout << "\n";
}
ll mod_pow(ll x, ll n, ll m = mod) {
    if (n < 0) {
        ll res = mod_pow(x, -n, m);
        return mod_pow(res, m - 2, m);
    }
    if (abs(x) >= m)x %= m;
    if (x < 0)x += m;
    //if (x == 0)return 0;
    ll res = 1;
    while (n) {
        if (n & 1)res = res * x % m;
        x = x * x % m; n >>= 1;
    }
    return res;
}
//mod should be <2^31
struct modint {
    int n;
    modint() :n(0) { ; }
    modint(ll m) {
        if (m < 0 || mod <= m) {
            m %= mod; if (m < 0)m += mod;
        }
        n = m;
    }
    operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
bool operator<(modint a, modint b) { return a.n < b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= (int)mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += (int)mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
    if (n == 0)return modint(1);
    modint res = (a * a) ^ (n / 2);
    if (n % 2)res = res * a;
    return res;
}

ll inv(ll a, ll p) {
    return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
    fact[0] = modint(1);
    for (int i = 0; i < max_n - 1; i++) {
        fact[i + 1] = fact[i] * modint(i + 1);
    }
    factinv[max_n - 1] = modint(1) / fact[max_n - 1];
    for (int i = max_n - 2; i >= 0; i--) {
        factinv[i] = factinv[i + 1] * modint(i + 1);
    }
}
modint comb(int a, int b) {
    if (a < 0 || b < 0 || a < b)return 0;
    return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
    if (a < 0 || b < 0 || a < b)return 0;
    return fact[a] * factinv[a - b];
}

ll gcd(ll a, ll b) {
    a = abs(a); b = abs(b);
    if (a < b)swap(a, b);
    while (b) {
        ll r = a % b; a = b; b = r;
    }
    return a;
}
template<typename T>
void addv(vector<T>& v, int loc, T val) {
    if (loc >= v.size())v.resize(loc + 1, 0);
    v[loc] += val;
}
/*const int mn = 2000005;
bool isp[mn];
vector<int> ps;
void init() {
    fill(isp + 2, isp + mn, true);
    for (int i = 2; i < mn; i++) {
        if (!isp[i])continue;
        ps.push_back(i);
        for (int j = 2 * i; j < mn; j += i) {
            isp[j] = false;
        }
    }
}*/

//[,val)
template<typename T>
auto prev_itr(set<T>& st, T val) {
    auto res = st.lower_bound(val);
    if (res == st.begin())return st.end();
    res--; return res;
}

//[val,)
template<typename T>
auto next_itr(set<T>& st, T val) {
    auto res = st.lower_bound(val);
    return res;
}
using mP = pair<modint, modint>;
mP operator+(mP a, mP b) {
    return { a.first + b.first,a.second + b.second };
}
mP operator+=(mP& a, mP b) {
    a = a + b; return a;
}
mP operator-(mP a, mP b) {
    return { a.first - b.first,a.second - b.second };
}
mP operator-=(mP& a, mP b) {
    a = a - b; return a;
}
LP operator+(LP a, LP b) {
    return { a.first + b.first,a.second + b.second };
}
LP operator+=(LP& a, LP b) {
    a = a + b; return a;
}
LP operator-(LP a, LP b) {
    return { a.first - b.first,a.second - b.second };
}
LP operator-=(LP& a, LP b) {
    a = a - b; return a;
}

mt19937 mt(time(0));

const string drul = "DRUL";
string senw = "SENW";
//DRUL,or SENW
//int dx[4] = { 1,0,-1,0 };
//int dy[4] = { 0,1,0,-1 };

//------------------------------------

int dist[105][105][2];
void solve() {
    int x, y, p, q; cin >> x >> y >> p >> q;
    rep(i, x + 1)rep(j, y + 1)rep(k, 2)dist[i][j][k] = mod17;
    auto isok = [&](int cs, int cw) {
        if (cs > 0 && cs + q < cw)return false;
        return true;
    };
    using ar = array<int, 3>;
    queue<ar> que;
    que.push({ x,y,0 });
    dist[x][y][0] = 0;
    while (!que.empty()) {
        ar a = que.front(); que.pop();
        int s0 = a[0];
        int w0 = a[1];
        int s1 = x - s0;
        int w1 = y - w0;
        int nd = dist[a[0]][a[1]][a[2]] + 1;
        if (a[2] == 0) {
            rep(i, p + 1)rep(j, p + 1) {
                if (i > s0)continue;
                if (j > w0)continue;
                if (i + j > p)continue;
                //if (!isok(i, j))continue;
                if (!isok(s0 - i, w0 - j))continue;
                //if (!isok(s1 + i, w1 + j))continue;
                int ni = s0 - i;
                int nj = w0 - j;
                int nk = 1;
                if (nd < dist[ni][nj][nk]) {
                    dist[ni][nj][nk] = nd;
                    que.push({ ni,nj,nk });
                }
            }
        }
        else {
            rep(i, p + 1)rep(j, p + 1) {
                if (i > s1)continue;
                if (j > w1)continue;
                if (i + j > p)continue;
                //if (!isok(i, j))continue;
                if (!isok(s1 - i, w1 - j))continue;
                //if (!isok(s0 + i, w0 + j))continue;
                int ni = s0 + i;
                int nj = w0 + j;
                int nk = 0;
                if (nd < dist[ni][nj][nk]) {
                    dist[ni][nj][nk] = nd;
                    que.push({ ni,nj,nk });
                }
            }
        }
    }
    int ans = mod17;
    rep(j, y + 1)rep(k,2)chmin(ans, dist[0][j][k]);
    if (ans == mod17)ans = -1;
    cout << ans << "\n";
}



signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed<<setprecision(10);
    //init_f();
    //init();
    //while(true)
    //expr();
    //int t; cin >> t; rep(i, t)
    solve();
    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 12076kb

input:

4 4 3 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 4ms
memory: 12120kb

input:

3 5 2 0

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 4ms
memory: 11888kb

input:

2 5 1 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 0
Accepted
time: 2ms
memory: 11836kb

input:

1 1 1 0

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 0ms
memory: 11868kb

input:

3 3 1 1

output:

7

result:

ok 1 number(s): "7"

Test #6:

score: 0
Accepted
time: 4ms
memory: 11840kb

input:

3 3 2 1

output:

3

result:

ok 1 number(s): "3"

Test #7:

score: 0
Accepted
time: 0ms
memory: 12068kb

input:

10 9 1 10

output:

19

result:

ok 1 number(s): "19"

Test #8:

score: 0
Accepted
time: 0ms
memory: 11904kb

input:

15 20 2 5

output:

27

result:

ok 1 number(s): "27"

Test #9:

score: 0
Accepted
time: 0ms
memory: 11916kb

input:

18 40 16 7

output:

5

result:

ok 1 number(s): "5"

Test #10:

score: 0
Accepted
time: 0ms
memory: 11920kb

input:

60 60 8 1

output:

27

result:

ok 1 number(s): "27"

Test #11:

score: 0
Accepted
time: 4ms
memory: 11944kb

input:

60 60 8 4

output:

27

result:

ok 1 number(s): "27"

Test #12:

score: 0
Accepted
time: 0ms
memory: 11888kb

input:

60 60 8 8

output:

25

result:

ok 1 number(s): "25"

Test #13:

score: 0
Accepted
time: 0ms
memory: 12016kb

input:

60 60 16 1

output:

13

result:

ok 1 number(s): "13"

Test #14:

score: 0
Accepted
time: 0ms
memory: 12232kb

input:

60 60 16 8

output:

11

result:

ok 1 number(s): "11"

Test #15:

score: 0
Accepted
time: 3ms
memory: 11956kb

input:

60 60 16 16

output:

11

result:

ok 1 number(s): "11"

Test #16:

score: 0
Accepted
time: 0ms
memory: 11948kb

input:

60 60 16 24

output:

9

result:

ok 1 number(s): "9"

Test #17:

score: 0
Accepted
time: 0ms
memory: 12124kb

input:

75 15 1 1

output:

175

result:

ok 1 number(s): "175"

Test #18:

score: 0
Accepted
time: 4ms
memory: 11880kb

input:

50 100 1 0

output:

-1

result:

ok 1 number(s): "-1"

Test #19:

score: 0
Accepted
time: 2ms
memory: 11980kb

input:

100 100 10 10

output:

35

result:

ok 1 number(s): "35"

Test #20:

score: 0
Accepted
time: 5ms
memory: 11972kb

input:

100 100 10 1

output:

37

result:

ok 1 number(s): "37"

Test #21:

score: 0
Accepted
time: 5ms
memory: 11980kb

input:

100 100 10 20

output:

33

result:

ok 1 number(s): "33"

Test #22:

score: 0
Accepted
time: 3ms
memory: 11984kb

input:

100 100 10 30

output:

31

result:

ok 1 number(s): "31"

Test #23:

score: 0
Accepted
time: 6ms
memory: 11984kb

input:

100 100 10 80

output:

21

result:

ok 1 number(s): "21"

Test #24:

score: 0
Accepted
time: 0ms
memory: 11976kb

input:

100 100 1 100

output:

199

result:

ok 1 number(s): "199"

Test #25:

score: 0
Accepted
time: 0ms
memory: 12044kb

input:

100 100 5 0

output:

95

result:

ok 1 number(s): "95"

Test #26:

score: 0
Accepted
time: 10ms
memory: 12224kb

input:

100 100 25 3

output:

13

result:

ok 1 number(s): "13"

Test #27:

score: 0
Accepted
time: 14ms
memory: 11952kb

input:

100 100 30 4

output:

11

result:

ok 1 number(s): "11"

Test #28:

score: 0
Accepted
time: 2ms
memory: 11968kb

input:

95 100 3 3

output:

125

result:

ok 1 number(s): "125"

Test #29:

score: 0
Accepted
time: 31ms
memory: 12016kb

input:

98 99 50 6

output:

5

result:

ok 1 number(s): "5"

Test #30:

score: 0
Accepted
time: 31ms
memory: 12272kb

input:

100 100 45 4

output:

7

result:

ok 1 number(s): "7"

Test #31:

score: 0
Accepted
time: 32ms
memory: 12020kb

input:

100 100 40 39

output:

7

result:

ok 1 number(s): "7"

Test #32:

score: 0
Accepted
time: 31ms
memory: 12176kb

input:

100 100 45 19

output:

7

result:

ok 1 number(s): "7"

Test #33:

score: 0
Accepted
time: 61ms
memory: 12268kb

input:

100 100 49 99

output:

5

result:

ok 1 number(s): "5"

Test #34:

score: 0
Accepted
time: 56ms
memory: 12280kb

input:

100 100 49 100

output:

5

result:

ok 1 number(s): "5"

Test #35:

score: 0
Accepted
time: 55ms
memory: 12304kb

input:

100 100 49 98

output:

5

result:

ok 1 number(s): "5"

Test #36:

score: 0
Accepted
time: 60ms
memory: 12076kb

input:

100 100 49 97

output:

5

result:

ok 1 number(s): "5"

Test #37:

score: 0
Accepted
time: 55ms
memory: 12040kb

input:

100 100 49 96

output:

5

result:

ok 1 number(s): "5"

Test #38:

score: 0
Accepted
time: 55ms
memory: 12040kb

input:

100 100 49 95

output:

5

result:

ok 1 number(s): "5"

Test #39:

score: 0
Accepted
time: 99ms
memory: 12020kb

input:

100 100 100 0

output:

1

result:

ok 1 number(s): "1"

Test #40:

score: 0
Accepted
time: 4ms
memory: 11912kb

input:

1 100 1 0

output:

1

result:

ok 1 number(s): "1"

Test #41:

score: 0
Accepted
time: 4ms
memory: 11904kb

input:

90 100 5 5

output:

87

result:

ok 1 number(s): "87"

Test #42:

score: 0
Accepted
time: 4ms
memory: 11920kb

input:

100 1 1 0

output:

199

result:

ok 1 number(s): "199"

Test #43:

score: 0
Accepted
time: 11ms
memory: 12152kb

input:

94 61 22 35

output:

9

result:

ok 1 number(s): "9"

Test #44:

score: 0
Accepted
time: 6ms
memory: 11936kb

input:

61 92 36 6

output:

7

result:

ok 1 number(s): "7"

Test #45:

score: 0
Accepted
time: 0ms
memory: 12028kb

input:

73 89 12 4

output:

57

result:

ok 1 number(s): "57"

Test #46:

score: 0
Accepted
time: 4ms
memory: 11928kb

input:

71 80 4 3

output:

-1

result:

ok 1 number(s): "-1"

Test #47:

score: 0
Accepted
time: 0ms
memory: 11908kb

input:

44 75 2 31

output:

85

result:

ok 1 number(s): "85"

Test #48:

score: 0
Accepted
time: 4ms
memory: 11908kb

input:

48 62 5 18

output:

35

result:

ok 1 number(s): "35"

Test #49:

score: 0
Accepted
time: 11ms
memory: 11872kb

input:

73 100 22 49

output:

9

result:

ok 1 number(s): "9"

Extra Test:

score: 0
Extra Test Passed