QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#280168#7789. Outro: True Love Waitsucup-team1469#WA 1ms3640kbC++208.6kb2023-12-09 14:14:292023-12-09 14:14:29

Judging History

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

  • [2023-12-09 14:14:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3640kb
  • [2023-12-09 14:14:29]
  • 提交

answer

#line 1 "main.cpp"
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tag_and_trait.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// namespace gt = __gnu_pbds;
#define IS_MULTITEST 1

using namespace std;

#line 2 "/Library/angel/math/modint.hpp"

#line 2 "/Library/Nyaan/modint/montgomery-modint.hpp"



template <uint32_t mod>
struct LazyMontgomeryModInt {
  using mint = LazyMontgomeryModInt;
  using i32 = int32_t;
  using u32 = uint32_t;
  using u64 = uint64_t;

  static constexpr u32 get_r() {
    u32 ret = mod;
    for (i32 i = 0; i < 4; ++i) ret *= 2 - mod * ret;
    return ret;
  }

  static constexpr u32 r = get_r();
  static constexpr u32 n2 = -u64(mod) % mod;
  static_assert(r * mod == 1, "invalid, r * mod != 1");
  static_assert(mod < (1 << 30), "invalid, mod >= 2 ^ 30");
  static_assert((mod & 1) == 1, "invalid, mod % 2 == 0");

  u32 a;

  constexpr LazyMontgomeryModInt() : a(0) {}
  constexpr LazyMontgomeryModInt(const int64_t &b)
      : a(reduce(u64(b % mod + mod) * n2)){};

  static constexpr u32 reduce(const u64 &b) {
    return (b + u64(u32(b) * u32(-r)) * mod) >> 32;
  }

  constexpr mint &operator+=(const mint &b) {
    if (i32(a += b.a - 2 * mod) < 0) a += 2 * mod;
    return *this;
  }

  constexpr mint &operator-=(const mint &b) {
    if (i32(a -= b.a) < 0) a += 2 * mod;
    return *this;
  }

  constexpr mint &operator*=(const mint &b) {
    a = reduce(u64(a) * b.a);
    return *this;
  }

  constexpr mint &operator/=(const mint &b) {
    *this *= b.inverse();
    return *this;
  }

  constexpr mint operator+(const mint &b) const { return mint(*this) += b; }
  constexpr mint operator-(const mint &b) const { return mint(*this) -= b; }
  constexpr mint operator*(const mint &b) const { return mint(*this) *= b; }
  constexpr mint operator/(const mint &b) const { return mint(*this) /= b; }
  constexpr bool operator==(const mint &b) const {
    return (a >= mod ? a - mod : a) == (b.a >= mod ? b.a - mod : b.a);
  }
  constexpr bool operator!=(const mint &b) const {
    return (a >= mod ? a - mod : a) != (b.a >= mod ? b.a - mod : b.a);
  }
  constexpr mint operator-() const { return mint() - mint(*this); }

  constexpr mint pow(u64 n) const {
    mint ret(1), mul(*this);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  
  constexpr mint inverse() const { return pow(mod - 2); }

  friend ostream &operator<<(ostream &os, const mint &b) {
    return os << b.get();
  }

  friend istream &operator>>(istream &is, mint &b) {
    int64_t t;
    is >> t;
    b = LazyMontgomeryModInt<mod>(t);
    return (is);
  }
  
  constexpr u32 get() const {
    u32 ret = reduce(a);
    return ret >= mod ? ret - mod : ret;
  }

  static constexpr u32 get_mod() { return mod; }
};
#line 2 "/Library/Nyaan/modulo/binomial.hpp"

template <typename T>
struct Binomial {
  vector<T> f, g, h;
  Binomial(int MAX = 0) {
    assert(T::get_mod() != 0 && "Binomial<mint>()");
    f.resize(1, T{1});
    g.resize(1, T{1});
    h.resize(1, T{1});
    while (MAX >= (int)f.size()) extend();
  }

  void extend() {
    int n = f.size();
    int m = n * 2;
    f.resize(m);
    g.resize(m);
    h.resize(m);
    for (int i = n; i < m; i++) f[i] = f[i - 1] * T(i);
    g[m - 1] = f[m - 1].inverse();
    h[m - 1] = g[m - 1] * f[m - 2];
    for (int i = m - 2; i >= n; i--) {
      g[i] = g[i + 1] * T(i + 1);
      h[i] = g[i] * f[i - 1];
    }
  }

  T fac(int i) {
    if (i < 0) return T(0);
    while (i >= (int)f.size()) extend();
    return f[i];
  }

  T finv(int i) {
    if (i < 0) return T(0);
    while (i >= (int)g.size()) extend();
    return g[i];
  }

  T inv(int i) {
    if (i < 0) return -inv(-i);
    while (i >= (int)h.size()) extend();
    return h[i];
  }

  T C(int n, int r) {
    if (n < 0 || n < r || r < 0) return T(0);
    return fac(n) * finv(n - r) * finv(r);
  }

  inline T operator()(int n, int r) { return C(n, r); }

  template <typename I>
  T multinomial(const vector<I>& r) {
    static_assert(is_integral<I>::value == true);
    int n = 0;
    for (auto& x : r) {
      if (x < 0) return T(0);
      n += x;
    }
    T res = fac(n);
    for (auto& x : r) res *= finv(x);
    return res;
  }

  template <typename I>
  T operator()(const vector<I>& r) {
    return multinomial(r);
  }

  T C_naive(int n, int r) {
    if (n < 0 || n < r || r < 0) return T(0);
    T ret = T(1);
    r = min(r, n - r);
    for (int i = 1; i <= r; ++i) ret *= inv(i) * (n--);
    return ret;
  }

  T P(int n, int r) {
    if (n < 0 || n < r || r < 0) return T(0);
    return fac(n) * finv(n - r);
  }

  // [x^r] 1 / (1-x)^n
  T H(int n, int r) {
    if (n < 0 || r < 0) return T(0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};
#line 5 "/Library/angel/math/modint.hpp"

using Modint1000000007 = LazyMontgomeryModInt<1000000007>;
using Binomial1000000007 = Binomial<Modint1000000007>;
using Modint998244353 = LazyMontgomeryModInt<998244353>;
using Binomial998244353 = Binomial<Modint998244353>;
#line 11 "main.cpp"

#pragma region Macros
// clang-format off
using ll = long long; using uint = unsigned int; using ull = unsigned long long;
using i32 = int; using i64 = ll; using u32 = uint; using u64 = ull;
using i128 = __int128_t; using u128 = __uint128_t;
using Str = string;
template <class T> using Vec = vector<T>;
template <class T> using RevPriq = priority_queue<T, vector<T>, greater<T>>;
constexpr std::array<std::pair<int, int>, 4> dxy4 = {{{-1, 0}, {0, 1}, {1, 0}, {0, -1}}};
constexpr std::array<std::pair<int, int>, 8> dxy8 = {
    {{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}}};
constexpr int inf32 = 1 << 30; constexpr ll inf64 = 1ll << 60;
constexpr char eoln = '\n';
#define L(i, l, r) for (int i = (l); i < (r); ++i)
#define R(i, l, r) for (int i = (r) - 1; i >= (l); --i)
#define ALL(x) (x).begin(), (x).end()
#define mem(a, x) memset((a), (x), sizeof(a))
#define sz(a) (int)((a).size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
// clang-format on
#pragma endregion

// Coding Space

// vars

// funcs

using Fp = Modint1000000007;

Fp ml(ll n) {
    return (Fp(4) / Fp(3)) * Fp(4).pow(n - 1) - Fp(4) / Fp(3);
}

void main_() {
    Str S, T;
    cin >> S >> T;
    int k;
    cin >> k;
    if (sz(S) < sz(T)) S = Str(sz(T) - sz(S), '0') + S;
    else T = Str(sz(S) - sz(T), '0') + T;
    int N = sz(S);
    L(i, 0, N) {
        if (S[i] == T[i]) S[i] = T[i] = '0';
        else S[i] = '0', T[i] = '1';
    }
    reverse(ALL(S));
    reverse(ALL(T));
    while (not S.empty()) {
        if (S.back() == '0' and T.back() == '0') {
            S.pop_back();
            T.pop_back();
        } else {
            break;
        }
    }
    reverse(ALL(S));
    reverse(ALL(T));
    N = sz(S);
    if (N == 0) {
        cout << ml(k) << endl;
    } else {
        int c = 0, f = 0;
        R(i, 0, N) {
            if (T[i] == '0') ++c;
            else {
                f = i;
                break;
            }
        }
        if (k > c / 2 + 1) {
            cout << -1 << endl;
            return;
        }

        cerr << S << ' ' << T << endl;
        Fp base = 0;
        if (N % 2 == 1) {
            S = '0' + S;
            T = '0' + T;
            ++f;
            ++N;
        }
        for (int i = 0; i < N; i += 2) {
            Fp v = ml(N / 2 - i / 2);
            if (T[i] == '0' and T[i + 1] == '1') base += v + 1;
            else if (T[i] == '1' and T[i + 1] == '1') base += Fp(2) * v + 2;
            else if (T[i] == '1') base += Fp(3) * v + 3;
        }
        Fp iad = 0;
        L(i, 0, k - 1) {
            iad += ml(i + 2);
        }
        cout << base + iad << endl;
    }
}

set<pair<int, int>> s;
map<int, int> c;

void main_2() {
    int n = 0;
    int test = 100000;
    while (test--) {
        ++c[n];
        L(i, 0, 30) {
            if (s.find(minmax(n, n xor (1 << i))) == s.end()) {
                s.insert(minmax(n, n xor (1 << i)));
                n = n xor (1 << i);
                break;
            }
        }
    }
    for (auto [a, b] : c) cout << bitset<11>(a) << ' ' << b << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    if constexpr (IS_MULTITEST == 0) {
        main_2();
        // main_();
    } else {
        // multitest (cf-style)
        int T;
        cin >> T;
        while (T--) {
            main_();
            cout << flush;
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3572kb

input:

4
1 10 1
1 10 2
100 0 2
11 11 3

output:

2
-1
9
20

result:

ok 4 number(s): "2 -1 9 20"

Test #2:

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

input:

1
0 0 1

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

100
110111 11111 1
10110 101101 1
11010 111111 1
100110 1 1
10010 11010 1
1100 10111 1
100100 111110 1
101110 101100 1
1011 10110 1
110100 1110 1
11010 11000 1
11110 1000 1
111000 11101 1
110 1001 1
101010 11000 1
10 111110 1
110001 101000 1
1010 1000 1
10101 11 1
111011 11010 1
110001 100000 1
1100...

output:

78
59
69
70
15
38
39
3
32
60
3
29
69
12
45
52
37
3
29
64
22
39
54
69
65
27
33
76
34
18
57
13
81
15
23
70
69
36
18
23
29
42
69
54
6
0
63
3
29
15
10
16
80
24
37
59
71
13
23
31
21
34
23
48
21
47
7
44
42
3
37
75
59
29
55
39
29
28
29
70
55
16
54
47
24
18
79
60
8
26
64
58
32
6
8
37
2
68
42
44

result:

ok 100 numbers

Test #4:

score: 0
Accepted
time: 1ms
memory: 3568kb

input:

100
10011111 111 2
1011101100 1000000100 1
100011111 1001001111 1
1001100101 1100100001 1
10101000 10000100 1
1011110101 100011101 1
110100001 111011010 1
1101001100 1111101101 1
1001101 11011010 1
1101110110 1101011000 1
110011001 1100001111 2
1001111001 1011001111 1
1001110 1101110100 2
1110110100...

output:

295
248
788
431
73
930
144
319
283
76
-1
305
-1
-1
86
-1
312
293
1293
433
1179
0
884
963
1215
576
-1
1132
499
811
864
949
1322
406
526
862
-1
447
1203
1238
873
-1
-1
1131
1108
438
134
359
80
740
1057
752
31
950
1093
1261
650
235
996
876
504
925
1344
450
1010
273
-1
1144
1041
717
-1
164
-1
11
798
419...

result:

ok 100 numbers

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3640kb

input:

1000
1010011001 1100000000 1
1111001110 100100011 1
10000001 1110100110 1
1001000010 1111011110 1
11110001 101101110 1
10110001 110010 1
110111100 1111011111 1
1010101010 1111110000 1
11010110 11000110 1
1101101100 10001101 1
1101000110 111100110 3
1101100 10110 1
1001101001 10010001 1
1000110100 11...

output:

633
1267
752
627
629
257
1173
465
21
916
1365
145
1250
1006
155
783
412
684
400
1126
1204
185
298
932
535
246
1094
325
272
-1
-1
389
164
-1
-1
644
436
1271
261
741
351
212
985
426
236
1356
952
1256
1039
911
709
547
1349
142
229
1077
538
48
1089
378
1152
524
218
1161
485
884
751
299
206
268
95
933
76...

result:

wrong answer 11th numbers differ - expected: '1361', found: '1365'