QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#537874#7789. Outro: True Love WaitsRepeaterWA 1ms3868kbC++201.6kb2024-08-30 19:16:442024-08-30 19:16:45

Judging History

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

  • [2024-08-30 19:16:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3868kb
  • [2024-08-30 19:16:44]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

constexpr int P = 998244353;

int mp[4][4];

i64 power(i64 a, i64 b)
{
    i64 res = 1;
    for( ; b; b >>= 1, a = a * a % P)
        if(b & 1) res = res * a % P;

    return res;
}

void repeater()
{
    std::string s, t; std::cin >> s >> t;
    int k; std::cin >> k;

    if(s == t)
    {
        std::cout << ((power(4, k) - 1) * power(3, P - 2) - 1) % P << "\n";
        return;
    }

    int len = std::max((int)s.size(), (int)t.size());
    len += len & 1;

    std::ranges::reverse(s);
    std::ranges::reverse(t);
    s += std::string(len - (int)s.size(), '0');
    t += std::string(len - (int)t.size(), '0');

    int cnt = 0;
    for(int i = 1; i < len; i += 2)
    {
        if(s[i] != t[i] && s[i - 1] != t[i - 1]) break;
        cnt++;
    }

    if(cnt < k - 1)
    {
        std::cout << -1 << "\n";
        return;
    }

    i64 ans = 0;
    for(i64 i = 1, j = 1; i < len; i += 2, j = j * 5 % P)
    {
        int a = (s[i] - '0') * 2 + (s[i - 1] - '0');
        int b = (t[i] - '0') * 2 + (t[i - 1] - '0');

        ans += mp[a][b] * j;
        ans %= P;
    }
    ans += ((power(4, k) - 1) * power(3, P - 2) - 1) % P;
    ans %= P;
    std::cout << ans << "\n";;
}

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

    mp[0][1] = 1, mp[0][2] = 3, mp[0][3] = 2;
    mp[1][0] = 1, mp[1][2] = 2, mp[1][3] = 3;
    mp[2][0] = 3, mp[2][1] = 2, mp[2][3] = 1;
    mp[3][0] = 2, mp[3][1] = 3, mp[3][2] = 1;

    int t; std::cin >> t;
    while(t--) repeater();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3600kb

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

input:

1
0 0 1

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

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:

90
67
81
82
15
42
43
3
36
68
3
33
81
12
53
60
41
3
33
76
26
43
62
81
77
31
37
88
38
18
65
13
93
15
27
82
81
40
18
27
33
50
81
62
6
0
75
3
33
15
10
16
92
28
41
67
83
13
27
35
25
38
27
56
25
55
7
52
50
3
41
87
67
33
63
43
33
32
33
82
63
16
62
55
28
18
91
68
8
30
76
66
36
6
8
41
2
80
50
52

result:

wrong answer 1st numbers differ - expected: '78', found: '90'