QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#270468#5537. Storing Eggsyuto1115#TL 207ms133716kbC++232.0kb2023-11-30 21:52:352023-11-30 21:52:35

Judging History

This is the latest submission verdict.

  • [2023-11-30 21:52:35]
  • Judged
  • Verdict: TL
  • Time: 207ms
  • Memory: 133716kb
  • [2023-11-30 21:52:35]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#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;
}

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];
  }
  const int C = 1000;
  auto toId = [&](int i, int j, int k) {
    return i * C * C + j * C + k;
  };
  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;
    rep(i, 3) {
      if(i == x) continue;
      if(v[x]-v[i] == 2) v[i] = 0;
    }
    return {toId(v[0], v[1], v[2]), d};
  };
  vector dp(3, vector(n+2, vector<unordered_map<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) for(auto [pos, val] : dp[i][j][l]) {
    //  cout << i << ' ' << j << ' ' << l << ' ' << pos << ' ' << val << endl;
      chmax(dp[ni][nj][l][pos], 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: 3864kb

input:

5 2
#....
.....
....#

output:

4.472135954999580

result:

ok found '4.4721360', expected '4.4721360', error '0.0000000'

Test #2:

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

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

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

input:

2 6
..
.#
..

output:

-1

result:

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

Test #5:

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

input:

1 2
.
.
.

output:

2.000000000000000

result:

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

Test #6:

score: 0
Accepted
time: 207ms
memory: 133716kb

input:

100 2
....................................................................................................
....................................................................................................
...............................................................................................

output:

99.020199959402220

result:

ok found '99.0202000', expected '99.0202000', error '0.0000000'

Test #7:

score: -100
Time Limit Exceeded

input:

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

output:


result: