QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#663782 | #5537. Storing Eggs | ucup-team3519# | WA | 95ms | 8528kb | C++17 | 4.0kb | 2024-10-21 17:20:09 | 2024-10-21 17:20:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define V vector
#define pb push_back
typedef double db;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout << fixed << setprecision(10);
int n, k; cin >> n >> k;
V<string> vs(3);
for(int i = 0; i < 3; i++) cin >> vs[i];
V<V<V<db>>> dp(n, V<V<db>>(k + 1, V<db>(1 << 6)));
auto sqr = [&](int a) -> LL {
return 1LL * a * a;
};
auto dis = [&](int a, int b, int c, int d) -> db {
return sqrt(sqr(a - c) + sqr(b - d));
};
auto self_dist = [&](int mask) -> db {
assert(mask != 0);
db ans = 1e10;
for(int i = 0; i <= 2; i++) {
for(int j = i + 1; j <= 2; j++) {
if((mask >> i & 1) && (mask >> j & 1)) {
ans = min(ans, (db)j - i);
}
}
}
return ans;
};
V<int> good_mask = {1, 2, 3, 4, 5, 6, 7, 1 + 32, 4 + 8};
auto dist = [&](int cur_mask, int to_mask, int cur_pos, int to_pos) -> db {
db ans = 1e10;
for(int i = 0; i <= 2; i++) {
if(cur_mask >> i & 1) {
for(int j = 0; j <= 1; j++) {
for(int k = 0; k <= 2; k++) {
if(to_mask >> (j * 3 + k) & 1) {
ans = min(ans, dis(k, to_pos - j, i, cur_pos));
}
}
}
}
}
ans = min(ans, self_dist(cur_mask));
assert(ans <= 1e9);
return ans;
};
auto n_mask = [&](int cur_mask, int to_mask, int cur_pos, int to_pos) -> int {
if(cur_pos == to_pos + 1 && cur_mask == 1 && (to_mask >> 5 & 1)) return 1 + 32;
if(cur_pos == to_pos + 1 && cur_mask == 4 && (to_mask >> 3 & 1)) return 4 + 8;
return cur_mask;
};
auto ok_chs = [&](int cur_mask, int cur_pos) -> bool {
assert(cur_mask != 0);
for(int i = 0; i <= 2; i++) {
if(cur_mask >> i & 1) {
if(vs[i][cur_pos] == '#') return 0;
}
}
return 1;
};
V<V<int>> ok_chs_tab(1 << 3, V<int>(n));
for(int i = 1; i < 1 << 3; i++) for(int j = 0; j < n; j++) ok_chs_tab[i][j] = ok_chs(i, j);
auto upd = [&](db &ans, db val) -> void {
ans = max(ans, val);
};
db ans = 0;
for(int i = 0; i < n; i++) {
//gen new
for(int mask = 1; mask < 1 << 3; mask++) {
if(__popcount(mask) > k) continue;
if(ok_chs(mask, i)) upd(dp[i][__popcount(mask)][mask], self_dist(mask));
if(__popcount(mask) == k) ans = max(ans, self_dist(mask));
}
//hav_close
for(int to_pos = 0; to_pos < i; to_pos++) {//n * n / 2 * k * 64 * 8 * (ok_chs + dist + n_mask)
for(auto to_mask : good_mask) {
for(int cur_mask = 1; cur_mask < 1 << 3; cur_mask++) {
db cur_dist = dist(cur_mask, to_mask, i, to_pos);
for(int hav = 0; hav <= k; hav++) {
if(dp[to_pos][hav][to_mask] <= 0.5) continue;
db n_dp = dp[to_pos][hav][to_mask];
if(__popcount(cur_mask) + hav > k) continue;
if(ok_chs_tab[cur_mask][i]) {
n_dp = min(n_dp, cur_dist);
upd(dp[i][hav + __popcount(cur_mask)][n_mask(cur_mask, to_mask, i, to_pos)], n_dp);
if(hav + __popcount(cur_mask) == k) {
upd(ans, n_dp);
}
}
}
}
}
}
}
// cout << dp[0][1][2] << endl;
// cout << dp[1][3][1 + 4 + 16] << endl;
// cout << dist(1 + 4, 2, 1, 0) << endl;
if(ans >= 0.5) cout << ans << endl;
else cout << -1 << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3872kb
input:
5 2 #.... ..... ....#
output:
4.4721359550
result:
ok found '4.4721360', expected '4.4721360', error '0.0000000'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
5 6 ##.## ##### .....
output:
1.0000000000
result:
ok found '1.0000000', expected '1.0000000', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
3 4 ..# ... ...
output:
1.4142135624
result:
ok found '1.4142136', expected '1.4142140', error '0.0000003'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
2 6 .. .# ..
output:
-1
result:
ok found '-1.0000000', expected '-1.0000000', error '-0.0000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
1 2 . . .
output:
2.0000000000
result:
ok found '2.0000000', expected '2.0000000', error '0.0000000'
Test #6:
score: 0
Accepted
time: 6ms
memory: 4032kb
input:
100 2 .................................................................................................... .................................................................................................... ...............................................................................................
output:
99.0201999594
result:
ok found '99.0202000', expected '99.0202000', error '0.0000000'
Test #7:
score: 0
Accepted
time: 9ms
memory: 4148kb
input:
100 3 .................................................................................................... .................................................................................................... ...............................................................................................
output:
49.0407993410
result:
ok found '49.0407993', expected '49.0407990', error '0.0000000'
Test #8:
score: -100
Wrong Answer
time: 95ms
memory: 8528kb
input:
100 100 .................................................................................................... .................................................................................................... .............................................................................................
output:
2.2360679775
result:
wrong answer 1st numbers differ - expected: '2.0000000', found: '2.2360680', error = '0.1180340'