Logo Wy Online Judge

WyOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#325#6. 「WyOJ Round 1」持 · 山海为肩__vector__1004058ms129904kbC++234.2kb2025-04-18 19:00:482025-04-18 19:00:49

answer

#include <bits/stdc++.h>

using namespace std;

// #define LOCK_GETCHAR
// #define USE_INT_128
// #undef DEBUG

#ifdef DEBUG
#include <moeebius/debug.hpp>
#else
#define debug(...) (void(0))
#define Debug(...) (void(0))
#endif

#define ENABLE_IF_INT , enable_if_t<_is_integer<T>, int> = 0
template <class T> constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <> constexpr bool _is_integer<bool> = false;
template <> constexpr bool _is_integer<char> = false;
#ifdef USE_INT_128
template <> constexpr bool _is_integer<__int128> = true;
template <> constexpr bool _is_integer<__uint128_t> = true;
#endif

#if !defined(_WIN32) && !defined(__CYGWIN__) && !defined(LOCK_GETCHAR)
#define getchar getchar_unlocked
#endif

#define il inline
#define mkp make_pair
#define fi first
#define se second
#define ssz(x) (signed((x).size()))
#define beg2ed(x) (x).begin(), (x).end()
#define _loop_i_t(j, k) make_signed_t<decltype((j) - (k))>
#define For(i, j, k) for (_loop_i_t(j, k) i = (j); i <= (k); ++i)
#define ForDown(i, j, k) for (_loop_i_t(j, k) i = (j); i >= decltype(i)(k); --i)
#define eb emplace_back
#ifndef ONLINE_JUDGE
#define FileIO(filename)                                                       \
  freopen(filename ".in", "r", stdin);                                         \
  freopen(filename ".out", "w", stdout)
#else
#define FileIO(filename) void(0)
#endif

using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using db = double;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#ifdef USE_INT_128
using lll = __int128_t;
using ulll = __uint128_t;
#endif

// clang-format off
constexpr il ll qpow(ll x, ull y, ll mod){ ll ans = 1; x %= mod; while (y) { if (y & 1) (ans *= x) %= mod; (x *= x) %= mod; y >>= 1; } return ans; }
template<typename T> constexpr il void cmin(T & x, const T &y){ x = min(x, y); }
template<typename T> constexpr il void cmax(T & x, const T &y){ x = max(x, y); }
template<typename T ENABLE_IF_INT> il void read(T &x){ x = 0; int f = 1; int c = getchar(); while (!isdigit(c)) { if (c == '-') f = -1; c = getchar(); } while (isdigit(c)) { x = x * 10 + (c - '0'); c = getchar(); } x *= f; }
template<typename T, typename ... Args> il void read(T &x, Args &... y){ read(x), read(y...); }
// clang-format on

// File head end

namespace {
constexpr ll MAXN = 1e5 + 5;
int n, m, cnt = 1, ch[MAXN * 12][3], a[MAXN][12], wi[MAXN];
vector<array<int, 25>> f[MAXN * 12];
void ins(int x) {
  int p = 1;
  For(i, 0, m - 1) {
    if (!ch[p][a[x][i]])
      ch[p][a[x][i]] = ++cnt;
    p = ch[p][a[x][i]];
  }
  if (f[p].empty())
    f[p].eb();
  f[p][0][12] += wi[x];
}
void dfs(int p, int dep) {
  if (dep == m)
    return;
  For(i, 0, 2) if (ch[p][i]) dfs(ch[p][i], dep + 1);
  ll U = qpow(3, m - dep, 998244353);
  f[p].resize(U);
  int lft = m - dep - 1;
  For(i, 0, 2) if (ch[p][i]) {
    assert(!f[ch[p][i]].empty());
    For(S, 0, (U / 3) - 1) For(u, 12 - lft, 12 + lft) {
      int val = f[ch[p][i]][S][u];
      For(o, 0, 2) {
        f[p][S + o * (U / 3)][u + (o == (i + 1) % 3) - (o == (i + 2) % 3)] +=
            val;
      }
    }
    f[ch[p][i]].clear(), f[ch[p][i]].shrink_to_fit();
  }
}
void Main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m;
  int sum = 0;
  For(i, 1, n) {
    db x;
    cin >> x, wi[i] = round(x * 1e6);
    sum += wi[i];
    For(j, 0, m - 1) {
      string s;
      cin >> s;
      if (s == "rock")
        a[i][j] = 0;
      else if (s == "paper")
        a[i][j] = 1;
      else
        a[i][j] = 2;
    }
    ins(i);
  }
  assert(sum == int(1e6));
  dfs(1, 0);
  int ans = -1, U = qpow(3, m, 998244353), best = -1;
  For(S, 0, U - 1) {
    int cur = 0;
    For(i, 12, 12 + m) cur += f[1][S][i];
    if (cur > best)
      best = cur, ans = S;
  }
  cout << fixed << setprecision(6) << best / 1e6 << '\n';
  vector<string> sol;
  For(i, 0, m - 1) {
    int o = ans % 3;
    if (o == 0)
      sol.eb("rock");
    else if (o == 1)
      sol.eb("paper");
    else
      sol.eb("scissors");
    ans /= 3;
  }
  reverse(sol.begin(), sol.end());
  for (auto s : sol)
    cout << s << ' ';
  cout << '\n';
}
} // namespace

signed main() { return Main(), 0; }

这程序好像有点Bug,我给组数据试试?

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 8ms
memory: 5680kb

input:

841 5
0.002262 paper rock rock scissors scissors
0.000665 rock paper paper scissors paper
0.001132 s...

output:

0.689135
paper paper rock rock paper 

result:

ok 6 tokens

Test #2:

score: 10
Accepted
time: 7ms
memory: 5724kb

input:

320 1
0.001734 rock
0.000432 rock
0.003306 scissors
0.000322 paper
0.000380 rock
0.000817 scissors
0...

output:

0.728099
rock 

result:

ok 2 tokens

Test #3:

score: 10
Accepted
time: 3ms
memory: 5588kb

input:

19 2
0.086520 scissors rock
0.028985 rock rock
0.056406 rock scissors
0.010732 scissors rock
0.04471...

output:

0.836348
scissors rock 

result:

ok 3 tokens

Test #4:

score: 10
Accepted
time: 817ms
memory: 128184kb

input:

100000 12
0.000008 rock rock rock scissors paper scissors paper paper paper scissors paper scissors
...

output:

0.578764
rock rock paper paper paper paper scissors paper scissors rock paper rock 

result:

ok 13 tokens

Test #5:

score: 10
Accepted
time: 383ms
memory: 53120kb

input:

82918 11
0.000009 paper rock rock scissors scissors paper rock paper rock rock paper
0.000000 scisso...

output:

0.582727
paper rock paper paper paper scissors rock paper scissors scissors rock 

result:

ok 12 tokens

Test #6:

score: 10
Accepted
time: 182ms
memory: 24804kb

input:

63157 10
0.000004 rock scissors paper scissors paper scissors rock paper rock scissors
0.000007 rock...

output:

0.587712
rock scissors rock paper rock rock rock paper rock paper 

result:

ok 11 tokens

Test #7:

score: 10
Accepted
time: 796ms
memory: 127940kb

input:

100000 12
0.000003 rock rock rock paper paper rock paper paper paper rock rock scissors
0.000001 pap...

output:

0.578665
paper rock scissors scissors rock paper scissors rock scissors scissors rock paper 

result:

ok 13 tokens

Test #8:

score: 10
Accepted
time: 342ms
memory: 51628kb

input:

72055 11
0.000006 rock scissors scissors rock scissors scissors scissors scissors rock scissors scis...

output:

0.584229
paper rock paper rock rock rock paper scissors scissors rock scissors 

result:

ok 12 tokens

Test #9:

score: 10
Accepted
time: 691ms
memory: 120072kb

input:

49463 12
0.000024 rock paper scissors paper rock scissors rock paper paper paper paper paper
0.00000...

output:

0.584658
rock paper scissors scissors paper scissors rock rock paper scissors rock paper 

result:

ok 13 tokens

Test #10:

score: 10
Accepted
time: 829ms
memory: 129904kb

input:

100000 12
0.000007 rock paper scissors paper paper scissors rock rock scissors rock scissors paper
0...

output:

0.578092
rock scissors paper scissors paper paper paper rock rock paper paper rock 

result:

ok 13 tokens

Extra Test:

score: 0
Extra Test Passed