QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#280126 | #7781. Sheep Eat Wolves | ucup-team135# | AC ✓ | 43ms | 4088kb | C++20 | 6.0kb | 2023-12-09 14:01:38 | 2024-10-14 07:46:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
struct S{
bool cur[4] = {}, inv[4] = {};
char first = '\0', last = '\0';
int len = 0;
void inverse() {
for (int i = 0; i < 4; ++i) swap(cur[i], inv[i]);
first = first ^ 'a' ^ 'b';
last = last ^ 'a' ^ 'b';
}
explicit S(char c): first(c), last(c), len(1) {
cur[1] = cur[2] = 1;
inv[1] = inv[2] = 1;
if (c == 'a') cur[0] = 1;
if (c == 'b') inv[0] = 1;
}
S() = default;
friend S unite(S a, S b) {
if (a.len == 0) return b;
if (b.len == 0) return a;
S res;
res.cur[0] = (a.cur[0] && b.cur[0]) || (a.cur[2] && a.last != b.first && b.cur[1]);
res.cur[1] = (a.cur[1] && b.cur[0]) || (a.cur[3] && a.last != b.first && b.cur[1]);
res.cur[2] = (a.cur[0] && b.cur[2]) || (a.cur[2] && a.last != b.first && b.cur[3]);
res.cur[3] = (a.cur[1] && b.cur[2]) || (a.cur[3] && a.last != b.first && b.cur[3]);
res.len = a.len + b.len;
res.first = a.first;
res.last = b.last;
return res;
}
};
template<typename T>
struct SegmentTree {
int n;
vector<T> data;
SegmentTree(int n2, const string& s) : n(2 << __lg(n2)), data(2 * n) {
for (int i = 0; i < n2; ++i) data[i + n] = T(s[i]);
for (int i = n - 1; i > 0; --i) data[i] = unite(data[2 * i], data[2 * i + 1]);
}
void set(int i) {
data[i += n].inverse();
for (i /= 2; i > 0; i /= 2) {
data[i] = unite(data[2 * i], data[2 * i + 1]);
}
}
T get(int l, int r) {
T lans = T(), rans = T();
for (l += n, r += n; l < r; l /= 2, r /= 2) {
if (l & 1) lans = unite(lans, data[l++]);
if (r & 1) rans = unite(data[--r], rans);
}
return unite(lans, rans);
}
};
void gen(int os, string cur, vector <string> &ans) {
if (os == 0) {
ans.push_back(cur);
return;
}
for (char c = 'a'; c <= 'c'; ++c) {
auto t = cur; t += c;
gen(os-1,t,ans);
}
}
vector <string> a;
vector <string> b,c;
string ans;
map<vector<string>,bool> u[4][4];
bool can(int len, int h, vector <string> cand) {
if ((int)cand.size()<=1) {
return true;
}
if (h == 0) {
return false;
}
if(u[len][h].count(cand)) return u[len][h][cand];
for (int i = 0; i + 2 <= len; ++i) {
for (auto e : b) {
vector <vector <string>>go(3);
for (auto x : cand) {
int cnt = 0;
for (int j = 0; j < 2; ++j) {
cnt += e[j]==x[i+j];
}
go[cnt].push_back(x);
}
bool ok = 1;
for (auto v : go) {
ok &= can(len, h - 1, v);
}
if (ok) {
u[len][h][cand]=true;
return true;
}
}
}
u[len][h][cand]=false;
return false;
}
int que=0;int n;
string guess(int l, int len, int h, vector <string> cand) {
assert(!cand.empty());
if ((int)cand.size()<=1) {
return cand.front();
}
if(h==0)assert(0);
for (int i = 0; i + 2 <= len; ++i) {
for (auto e : b) {
vector <vector <string>>go(3);
for (auto x : cand) {
int cnt = 0;
for (int j = 0; j < 2; ++j) {
cnt += e[j]==x[i+j];
}
go[cnt].push_back(x);
}
bool ok = 1;
for (auto v : go) {
ok &= can(len, h - 1, v);
}
if (ok) {
cout << "? " << l + i + 1 << ' ' << e << endl;++que;assert(que<=(4*n+2)/3);
int ans; cin >> ans;
return guess(l, len, h - 1, go[ans]);
}
}
}
assert(0);
}
const int inf = 1e9;
int f[3][3];
int dp[107][107][2];
int32_t main() {
int x,y;cin>>x>>y;
int p, q;cin>>p>>q;
for (int i = 0; i < 107; ++i) {
for (int j = 0; j < 107; ++j) {
for (int t = 0; t < 2; ++t) {
dp[i][j][t] = inf;
}
}
}
queue <array<int,3>>qu;qu.push({x,y,0});
dp[x][y][0] = 0;
auto check = [&] (int s, int w ) {
if (s == 0 || w <= s + q) {
return true;
}
else {
return false;
}
};
auto ok = [&] (int ls, int lw, int t) {
int rs = x - ls, rw = y - lw;
if (t == 0 && !check(rs,rw)) {
return false;
}
if (t == 1 && !check(ls,lw)) {
return false;
}
return true;
};
auto relax = [&] (int ls, int lw, int t, int d) {
if (d < dp[ls][lw][t]) {
dp[ls][lw][t] = d;
qu.push({ls,lw,t});
}
};
while (qu.size()) {
auto [ls, lw, t] = qu.front(); qu.pop();
if (ls == 0) {
cout << dp[ls][lw][t]<<endl;
exit(0);
}
int d = dp[ls][lw][t];
//cout << ls << ' ' << lw << ' ' << t << ' ' << d << endl;
int rs = x - ls, rw = y - lw;
if (t == 0) {
for (int s = 0; s <= ls; ++s) {
for (int w = 0; w <= lw; ++w) {
if (s + w <= p) {
if (ok(ls - s, lw - w, 1)) {
relax(ls - s, lw - w, 1, d+1);
}
}
}
}
}
else {
for (int s = 0; s <= rs; ++s) {
for (int w = 0; w <= rw; ++w) {
if (s + w <= p) {
if (ok(ls + s, lw + w, 0)) {
relax(ls + s, lw + w, 0,d+1);
}
}
}
}
}
}
cout<<-1<<endl;
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3796kb
input:
4 4 3 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3744kb
input:
3 5 2 0
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3964kb
input:
2 5 1 1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3932kb
input:
1 1 1 0
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3932kb
input:
3 3 1 1
output:
7
result:
ok 1 number(s): "7"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3968kb
input:
3 3 2 1
output:
3
result:
ok 1 number(s): "3"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3732kb
input:
10 9 1 10
output:
19
result:
ok 1 number(s): "19"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
15 20 2 5
output:
27
result:
ok 1 number(s): "27"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3800kb
input:
18 40 16 7
output:
5
result:
ok 1 number(s): "5"
Test #10:
score: 0
Accepted
time: 2ms
memory: 3704kb
input:
60 60 8 1
output:
27
result:
ok 1 number(s): "27"
Test #11:
score: 0
Accepted
time: 2ms
memory: 3960kb
input:
60 60 8 4
output:
27
result:
ok 1 number(s): "27"
Test #12:
score: 0
Accepted
time: 3ms
memory: 3740kb
input:
60 60 8 8
output:
25
result:
ok 1 number(s): "25"
Test #13:
score: 0
Accepted
time: 3ms
memory: 3744kb
input:
60 60 16 1
output:
13
result:
ok 1 number(s): "13"
Test #14:
score: 0
Accepted
time: 4ms
memory: 3748kb
input:
60 60 16 8
output:
11
result:
ok 1 number(s): "11"
Test #15:
score: 0
Accepted
time: 4ms
memory: 3848kb
input:
60 60 16 16
output:
11
result:
ok 1 number(s): "11"
Test #16:
score: 0
Accepted
time: 5ms
memory: 3692kb
input:
60 60 16 24
output:
9
result:
ok 1 number(s): "9"
Test #17:
score: 0
Accepted
time: 1ms
memory: 3932kb
input:
75 15 1 1
output:
175
result:
ok 1 number(s): "175"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
50 100 1 0
output:
-1
result:
ok 1 number(s): "-1"
Test #19:
score: 0
Accepted
time: 14ms
memory: 3808kb
input:
100 100 10 10
output:
35
result:
ok 1 number(s): "35"
Test #20:
score: 0
Accepted
time: 3ms
memory: 3796kb
input:
100 100 10 1
output:
37
result:
ok 1 number(s): "37"
Test #21:
score: 0
Accepted
time: 20ms
memory: 3988kb
input:
100 100 10 20
output:
33
result:
ok 1 number(s): "33"
Test #22:
score: 0
Accepted
time: 21ms
memory: 3988kb
input:
100 100 10 30
output:
31
result:
ok 1 number(s): "31"
Test #23:
score: 0
Accepted
time: 25ms
memory: 3856kb
input:
100 100 10 80
output:
21
result:
ok 1 number(s): "21"
Test #24:
score: 0
Accepted
time: 23ms
memory: 3796kb
input:
100 100 1 100
output:
199
result:
ok 1 number(s): "199"
Test #25:
score: 0
Accepted
time: 4ms
memory: 3964kb
input:
100 100 5 0
output:
95
result:
ok 1 number(s): "95"
Test #26:
score: 0
Accepted
time: 17ms
memory: 3956kb
input:
100 100 25 3
output:
13
result:
ok 1 number(s): "13"
Test #27:
score: 0
Accepted
time: 18ms
memory: 3960kb
input:
100 100 30 4
output:
11
result:
ok 1 number(s): "11"
Test #28:
score: 0
Accepted
time: 3ms
memory: 3956kb
input:
95 100 3 3
output:
125
result:
ok 1 number(s): "125"
Test #29:
score: 0
Accepted
time: 19ms
memory: 3736kb
input:
98 99 50 6
output:
5
result:
ok 1 number(s): "5"
Test #30:
score: 0
Accepted
time: 22ms
memory: 3820kb
input:
100 100 45 4
output:
7
result:
ok 1 number(s): "7"
Test #31:
score: 0
Accepted
time: 26ms
memory: 4008kb
input:
100 100 40 39
output:
7
result:
ok 1 number(s): "7"
Test #32:
score: 0
Accepted
time: 28ms
memory: 3864kb
input:
100 100 45 19
output:
7
result:
ok 1 number(s): "7"
Test #33:
score: 0
Accepted
time: 43ms
memory: 3920kb
input:
100 100 49 99
output:
5
result:
ok 1 number(s): "5"
Test #34:
score: 0
Accepted
time: 37ms
memory: 3800kb
input:
100 100 49 100
output:
5
result:
ok 1 number(s): "5"
Test #35:
score: 0
Accepted
time: 38ms
memory: 3796kb
input:
100 100 49 98
output:
5
result:
ok 1 number(s): "5"
Test #36:
score: 0
Accepted
time: 38ms
memory: 3800kb
input:
100 100 49 97
output:
5
result:
ok 1 number(s): "5"
Test #37:
score: 0
Accepted
time: 39ms
memory: 3868kb
input:
100 100 49 96
output:
5
result:
ok 1 number(s): "5"
Test #38:
score: 0
Accepted
time: 37ms
memory: 4088kb
input:
100 100 49 95
output:
5
result:
ok 1 number(s): "5"
Test #39:
score: 0
Accepted
time: 3ms
memory: 3848kb
input:
100 100 100 0
output:
1
result:
ok 1 number(s): "1"
Test #40:
score: 0
Accepted
time: 1ms
memory: 3976kb
input:
1 100 1 0
output:
1
result:
ok 1 number(s): "1"
Test #41:
score: 0
Accepted
time: 3ms
memory: 3716kb
input:
90 100 5 5
output:
87
result:
ok 1 number(s): "87"
Test #42:
score: 0
Accepted
time: 1ms
memory: 3796kb
input:
100 1 1 0
output:
199
result:
ok 1 number(s): "199"
Test #43:
score: 0
Accepted
time: 12ms
memory: 3832kb
input:
94 61 22 35
output:
9
result:
ok 1 number(s): "9"
Test #44:
score: 0
Accepted
time: 5ms
memory: 4008kb
input:
61 92 36 6
output:
7
result:
ok 1 number(s): "7"
Test #45:
score: 0
Accepted
time: 2ms
memory: 3804kb
input:
73 89 12 4
output:
57
result:
ok 1 number(s): "57"
Test #46:
score: 0
Accepted
time: 0ms
memory: 3736kb
input:
71 80 4 3
output:
-1
result:
ok 1 number(s): "-1"
Test #47:
score: 0
Accepted
time: 2ms
memory: 3956kb
input:
44 75 2 31
output:
85
result:
ok 1 number(s): "85"
Test #48:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
48 62 5 18
output:
35
result:
ok 1 number(s): "35"
Test #49:
score: 0
Accepted
time: 11ms
memory: 3808kb
input:
73 100 22 49
output:
9
result:
ok 1 number(s): "9"
Extra Test:
score: 0
Extra Test Passed