QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#270545 | #5537. Storing Eggs | yuto1115# | WA | 8ms | 6112kb | C++23 | 2.5kb | 2023-12-01 00:50:05 | 2023-12-01 00:50:07 |
Judging History
answer
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, s, n) for (ll i = ll(s); i < ll(n); i++)
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
#define all(a) a.begin(), a.end()
#define pb push_back
const int inf = 1e9;
const ll linf = 2e18;
template<class T>
bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
const int C = 1000;
inline int toId(int i, int j, int k) {
return i * C * C + j * C + k;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<string> s(3);
rep(i, 3) {
cin >> s[i];
s[i] = "." + s[i];
}
auto optimize = [](int pos, int y) -> int {
vi v(3);
v[0] = pos/(C*C);
v[1] = pos/C%C;
v[2] = pos%C;
int mx = max({v[0],v[1],v[2]});
rep(i, 3) {
assert(v[i] <= y);
if((y-v[i])*(y-v[i]) >= (y-mx)*(y-mx)+4) v[i] = 0;
}
return toId(v[0],v[1],v[2]);
};
auto next_pos = [&](int pos, int x, int y) -> P {
vi v(3);
v[0] = pos/(C*C);
v[1] = pos/C%C;
v[2] = pos%C;
int d = inf;
rep(i, 3) {
if(v[i] > 0) {
chmin<int>(d, (y-v[i])*(y-v[i])+(i-x)*(i-x));
}
}
v[x] = y;
pos = toId(v[0],v[1],v[2]);
return {optimize(pos,y), d};
};
vector dp(3, vector(n+2, vector<gp_hash_table<int, int>>(k+1)));
dp[0][1][0][0] = 1e9;
rep2(j, 1, n+1) rep(i, 3) {
int ni = i+1, nj = j;
if(ni == 3) {
ni = 0, ++nj;
}
rep(l, k+1) {
int mx = 0;
for(auto [_,val] : dp[i][j][l]) mx = max(mx, val);
for(auto [pos, val] : dp[i][j][l]) {
if(mx > 3 and val < mx / 2) continue;
// cout << i << ' ' << j << ' ' << l << ' ' << pos << ' ' << val << endl;
chmax(dp[ni][nj][l][optimize(pos,nj)], val);
if(l < k and s[i][j] == '.') {
auto [npos, d] = next_pos(pos, i, j);
chmax(dp[ni][nj][l + 1][npos], min(val, d));
}
}
}
}
int ans = -1;
for(auto [_, val] : dp[0][n+1][k]) {
chmax(ans, val);
}
if(ans == -1) {
cout << ans << endl;
} else {
cout << fixed << setprecision(15) << sqrt(ans) << endl;
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3688kb
input:
5 2 #.... ..... ....#
output:
4.472135954999580
result:
ok found '4.4721360', expected '4.4721360', error '0.0000000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3676kb
input:
5 6 ##.## ##### .....
output:
1.000000000000000
result:
ok found '1.0000000', expected '1.0000000', error '0.0000000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3828kb
input:
3 4 ..# ... ...
output:
1.414213562373095
result:
ok found '1.4142136', expected '1.4142140', error '0.0000003'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3472kb
input:
2 6 .. .# ..
output:
-1
result:
ok found '-1.0000000', expected '-1.0000000', error '-0.0000000'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
1 2 . . .
output:
2.000000000000000
result:
ok found '2.0000000', expected '2.0000000', error '0.0000000'
Test #6:
score: 0
Accepted
time: 8ms
memory: 5724kb
input:
100 2 .................................................................................................... .................................................................................................... ...............................................................................................
output:
99.020199959402220
result:
ok found '99.0202000', expected '99.0202000', error '0.0000000'
Test #7:
score: -100
Wrong Answer
time: 6ms
memory: 6112kb
input:
100 3 .................................................................................................... .................................................................................................... ...............................................................................................
output:
29.068883707497267
result:
wrong answer 1st numbers differ - expected: '49.0407990', found: '29.0688837', error = '0.4072510'