QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#610596#7789. Outro: True Love Waitsucup-team2179#WA 5ms23904kbC++202.0kb2024-10-04 16:33:282024-10-04 16:33:30

Judging History

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

  • [2024-10-04 16:33:30]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:23904kb
  • [2024-10-04 16:33:28]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define ll long long
#define db double
#define pii pair<int, int>
using namespace std;
const int N = 2e6 + 999, mod = 1e9+7;
int pos[N], p[N];
int qpow(int a, int b){
    int ret = 1;
    while(b){
        if(b & 1) ret = ret * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return ret;
}
int cal(int s){
    if(s == 1)
        return 0;
    s--;
    return 4 * (qpow(4, s) + mod - 1) % mod * qpow(3, mod - 2) % mod;
}
void solve(){
    string s, t;
    cin >> s >> t;
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    s.push_back('0'), t.push_back('0');
    while(s.length() < t.length())
        s.push_back('0');
    while(t.length() < s.length())
    t.push_back('0');
    int lt = t.size(), ls = s.size();
    for (int i = 0; i < min(ls, lt); i++)
        t[i] = (t[i] - '0') ^ (s[i] - '0') + '0';
    int k;
    cin >> k;
    int ans = 0;
    for (int i = lt - 1; i >= 2; i--){
        if(t[i] == '1'){
            ans += pos[i];
            ans %= mod;
        }
    }
    int lb = k * 2;
    for (int i = 0; i < lt; i++)
        if(t[i] == '1'){
            lb = i;
            break;
        }
    if(lb / 2 + 1 >= k){
        if(t[0] == '1' && t[1] == '1')
            ans += 2;
        else if(t[0] == '1')
            ans += 1;
        else if(t[1] == '1')
            ans += 3;
        else
            ans += cal(k);
        ans %= mod;
    }
    else
        ans = -1;
    cout << ans << '\n';
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    p[0] = 1;
    for (int i = 1; i <= 1e6; i++)
        p[i] = p[i - 1] * 4 % mod;
    pos[0] = 1;
    pos[1] = 3;
    for (int i = 2; i <= 1e6; i++){
        if(i & 1)
            pos[i] = (p[(i + 1) / 2] + mod - 1) % mod;
        else
            pos[i] = (pos[i - 2] + p[i  / 2]) % mod;
    }  
    int T;
    cin >> T;
    while(T--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 21384kb

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: 5ms
memory: 23904kb

input:

1
0 0 1

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 5ms
memory: 21592kb

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
101
69
70
15
38
39
3
42
102
3
29
69
22
87
104
37
3
29
64
22
39
106
69
65
27
43
86
44
18
99
23
81
15
23
70
69
36
18
23
29
84
69
106
6
0
63
3
29
15
20
16
80
24
37
101
71
23
23
41
21
44
23
90
21
89
7
86
84
3
37
85
101
29
107
39
29
28
29
70
107
16
106
89
24
18
79
102
8
26
64
100
42
6
8
37
2
68
84
86

result:

wrong answer 2nd numbers differ - expected: '59', found: '101'