QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#253032 | #5537. Storing Eggs | warner1129# | WA | 1ms | 3916kb | C++20 | 3.8kb | 2023-11-16 16:50:33 | 2023-11-16 16:50:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
template<class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); }
template<class T> void org(T l, T r) { while (l != r) cerr << ' ' << *l++; cerr << '\n'; }
#define debug(x...) dbg(#x, '=', x, '\n')
#define olist(x...) dbg(#x, '='), org(x)
#else
#define debug(...) ((void)0)
#define olist(...) ((void)0)
#endif
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using Pt = pair<i128, i128>;
template<class T>
inline constexpr T inf = numeric_limits<T>::max() / 2;
constexpr int mod = 998244353;
Pt operator+(Pt a, Pt b) { return {a.ff + b.ff, a.ss + b.ss}; }
Pt operator-(Pt a, Pt b) { return {a.ff - b.ff, a.ss - b.ss}; }
i128 operator^(Pt a, Pt b) { return a.ff * b.ss - a.ss * b.ff; }
i128 cro(Pt a, Pt b, Pt c) { return (b - a) ^ (c - a); }
template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); }
template<class... T> int add(T... x) { int t{}; return (((t += x) %= mod), ...), t; }
template<class... T> int mul(T... x) { i64 t{1}; return (((t *= x) %= mod), ...), t; }
void solve() {
int n, K;
cin >> n >> K;
vector dis(3, vector<i64>(n));
for (int i = 0; i < 3; i++)
for (int j = 0; j < n; j++) {
dis[i][j] = 1ll * i * i + 1ll * j * j;
}
vector<string> G(3);
int tot = 0;
for (auto &s : G) {
cin >> s;
tot += ranges::count(s, '.');
}
if (tot < K) {
cout << "-1\n";
return;
}
vector<int> mask(n);
for (int i = 0; i < n; i++) {
mask[i] = (G[0][i] == '#') * 4 + (G[1][i] == '#') * 2 + (G[2][i] == '#');
}
auto DP = [&](int L) -> int {
vector dp(n, array<int, 64>{});
auto check = [&](int a, int b, int d) {
auto getd = [&](int x, int y) {
int dx = (x % 3 - y % 3);
int dy = (x / 3 - y / 3);
return dx * dx + dy * dy;
};
for (int i = 0; i < 6; i++)
for (int j = 0; j < 6; j++) {
if ((a >> i & 1) and (b >> j & 1)) {
if (dis[abs(i % 3 - j % 3)][d - j / 3 + i / 3] < L)
return false;
}
if (i != j and (a >> i & 1) and (a >> j & 1) and getd(i, j) < L)
return false;
if (i != j and (b >> i & 1) and (b >> j & 1) and getd(i, j) < L)
return false;
}
return true;
};
int ans = 0;
for (int i = 0; i < n; i++) {
dp[i].fill(-1);
for (int s = 1; s < 64; s++) {
if ((mask[i] & s) or (i == 0 and (s >= 8))) continue;
int g = popcount((u64)s);
if (check(0, s, 0)) {
dp[i][s] = g;
}
for (int j = 0; j + 1 < i; j++)
for (int t = 1; t < 64; t++)
if (dp[j][t] != -1 and check(t, s, (i - j))) {
debug(j, i, bitset<3>(t), bitset<3>(s));
chmax(dp[i][s], dp[j][t] + g);
}
chmax(ans, dp[i][s]);
}
}
return ans;
};
int ans = *ranges::partition_point(views::iota(0, (int)1e6), [&](int x) {
return DP(x) >= K;
}) - 1;
cout << fixed << setprecision(10);
cout << sqrtl((long double)ans) << '\n';
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3916kb
input:
5 2 #.... ..... ....#
output:
4.4721359550
result:
ok found '4.4721360', expected '4.4721360', error '0.0000000'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3884kb
input:
5 6 ##.## ##### .....
output:
1.4142135624
result:
wrong answer 1st numbers differ - expected: '1.0000000', found: '1.4142136', error = '0.4142136'