QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#92272#4514. Schrödinger and PavlovKHIN50 ✓1230ms3740kbC++172.2kb2023-03-30 15:08:042023-03-30 15:08:08

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-30 15:08:08]
  • 评测
  • 测评结果:50
  • 用时:1230ms
  • 内存:3740kb
  • [2023-03-30 15:08:04]
  • 提交

answer

# include <cstdlib>
# include <tuple>
# include <utility>
# include <cassert>
# include <vector>
# include <algorithm>
# include <cstdio>
# include <iostream>

namespace khin {
  using namespace std;
  namespace main {
    inline namespace source {}
    namespace d { void main(); }
  }
}

int main() { khin::main::d::main(); }

namespace khin::main::d {
  namespace test_case {
    constexpr uint mod(1'000'000'007);
    constexpr uint n_max(5'000);
    struct box { char c; uint b; uint f; bool vis; };
    uint n; box b[n_max + 1]; uint ans;
    void main(ushort const x) {
      cin >> n;
      for (uint i(1); i <= n; ++i) cin >> b[i].c;
      for (uint i(1); i <= n; ++i) cin >> b[i].b;
      [] {
        vector<uint> c(1, n);
        while (b[c.back()].vis = true, !b[b[c.back()].b].vis)
          c.push_back(b[c.back()].b);
        for (uint const x : c) b[x].vis = false;
        c.erase(c.begin(), find(c.begin(), c.end(), b[c.back()].b));
        b[*min_element(c.begin(), c.end())].vis = true;
      } ();
      for (uint const x : { 0, 1 }) for (uint const y : { 0, 1 }) {
        for (uint i(1); i <= n; ++i) switch (b[i].c) {
          case 'C': b[i].f = 1; break;
          case '.': b[i].f = 0; break;
          case '?': b[i].f = (mod + 1) / 2; break;
          default : assert(false);
        }
        uint r(1);
        for (uint i(1); i <= n; ++i) {
          if (b[i].vis) {
            uint &p(b[i].f), &q(b[b[i].b].f);
            r = 1ul * r * (x ? p : 1 - p + mod) % mod;
            r = 1ul * r * (y ? q : 1 - q + mod) % mod;
            p = x && y, q = x || y;
          } else {
            uint &p(b[i].f), &q(b[b[i].b].f);
            uint const x(1ul * p * q % mod);
            uint const y((p + q - 1ul * p * q % mod + mod) % mod);
            tie(p, q) = make_pair(x, y);
          }
        }
        ans = (ans + 1ul * r * b[n].f) % mod;
      }
      for (uint i(1); i <= n; ++i)
        ans = ans * (b[i].c == '?' ? 2 : 1) % mod;
      printf("Case #%hu: %u\n", x, ans);
      fill(b + 1, b + n + 1, box()), ans = 0;
    }
  }
  void main() {
    ushort t; cin >> t;
    for (ushort i(1); i <= t; ++i) test_case::main(i);
  }
}

詳細信息

Test #1:

score: 8
Accepted
time: 17ms
memory: 3608kb

input:

1234
92
????????????????????????????????????????????????????????????????????????????????????????????
2 1 2 3 4 7 5 7 8 9 15 9 15 12 14 15 16 19 16 17 17 20 22 23 24 25 26 27 28 29 30 31 32 33 34 38 34 39 35 39 45 40 42 43 44 45 46 47 48 49 50 51 52 57 53 55 56 56 57 59 60 61 62 63 64 64 66 67 68 69 ...

output:

Case #1: 75340207
Case #2: 248320570
Case #3: 1
Case #4: 501005577
Case #5: 0
Case #6: 0
Case #7: 0
Case #8: 988185614
Case #9: 0
Case #10: 840220993
Case #11: 140130951
Case #12: 8
Case #13: 0
Case #14: 0
Case #15: 570065479
Case #16: 128
Case #17: 67108864
Case #18: 0
Case #19: 0
Case #20: 5605238...

result:

ok 1234 lines

Test #2:

score: 42
Accepted
time: 1230ms
memory: 3740kb

input:

1234
4693
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????...

output:

Case #1: 13595505
Case #2: 0
Case #3: 370024028
Case #4: 332957307
Case #5: 0
Case #6: 401898087
Case #7: 588719939
Case #8: 0
Case #9: 0
Case #10: 0
Case #11: 893344250
Case #12: 816205426
Case #13: 902710840
Case #14: 735342227
Case #15: 0
Case #16: 623834768
Case #17: 195615577
Case #18: 44692699...

result:

ok 1234 lines