QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#252998#5537. Storing Eggswarner1129#WA 9ms3752kbC++203.6kb2023-11-16 16:26:132023-11-16 16:26:14

Judging History

This is the latest submission verdict.

  • [2023-11-16 16:26:14]
  • Judged
  • Verdict: WA
  • Time: 9ms
  • Memory: 3752kb
  • [2023-11-16 16:26:13]
  • Submitted

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, 8>{});
        auto check = [&](int a, int b, int d) {
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++) {
                    if ((a >> i & 1) and (b >> j & 1)) {
                        if (dis[abs(i - j)][d] < L)
                            return false;
                    }
                    if (i != j and (a >> i & 1) and (a >> j & 1) and (i - j) * (i - j) < L)
                        return false;
                    if (i != j and (b >> i & 1) and (b >> j & 1) and (i - j) * (i - j) < L)
                        return false;
                }
            return true;
        };
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int s = 1; s < 8; s++) {
                if (mask[i] & s) continue;
                int g = popcount((u64)s);
                if (check(0, s, 0)) {
                    dp[i][s] = g;
                }
                for (int j = 0; j < i; j++)
                    for (int t = 1; t < 8; t++)
                        if (check(t, s, (i - j))) {
                            debug(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(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: 0ms
memory: 3588kb

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: 3620kb

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: 3596kb

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: 3404kb

input:

2 6
..
.#
..

output:

-1

result:

ok found '-1.0000000', expected '-1.0000000', error '-0.0000000'

Test #5:

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

input:

1 2
.
.
.

output:

2.0000000000

result:

ok found '2.0000000', expected '2.0000000', error '0.0000000'

Test #6:

score: 0
Accepted
time: 7ms
memory: 3584kb

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: 3696kb

input:

100 3
....................................................................................................
....................................................................................................
...............................................................................................

output:

49.0407993410

result:

ok found '49.0407993', expected '49.0407990', error '0.0000000'

Test #8:

score: -100
Wrong Answer
time: 7ms
memory: 3512kb

input:

100 100
....................................................................................................
....................................................................................................
.............................................................................................

output:

2.2360679775

result:

wrong answer 1st numbers differ - expected: '2.0000000', found: '2.2360680', error = '0.1180340'