QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#647916 | #7789. Outro: True Love Waits | Mcggvc | WA | 7ms | 12348kb | C++17 | 1.9kb | 2024-10-17 16:11:11 | 2024-10-17 16:11:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// typedef long long lld;
#define int long long
const int p = 1e9 + 7;
const int N = 1000005;
string s, t;
vector<int> op1, op;
int k, inv3;
const int h[] = {1, 2, 4, 3};
int fcalc[N], fc[N];
int powe(int a, int b) {
int base = 1;
while(b) {
if(b & 1) base = base * a % p;
a = a * a % p;
b >>= 1;
}
return base;
}
int calc(int n) {
if(n == op.size()) return 1;
if(fcalc[n]) return fcalc[n];
else return fcalc[n] = (calc(n + 1) * 4 + 1) % p;
}
inline int S(int sufz) {
return (fc[sufz] - 4) % p * inv3 % p;
}
int getans(int n) {
if(n == op.size() - 1) {
return h[op[n]];
}
int pertot = (h[op[n]] - 1) * calc(n + 1) % p;
return (pertot + getans(n + 1)) % p;
}
void solve() {
op.clear();
cin >> s >> t >> k;
int n = max(s.size(), t.size());
reverse(s.begin(), s.end());
reverse(t.begin(), t.end());
if(n % 2) n++;
// s.resize(n); t.resize(n);
while(s.size() < n) s.push_back('0');
while(t.size() < n) t.push_back('0');
for(int i = 0; i < n; i++) {
op1.push_back((s[i] - '0') ^ (t[i] - '0'));
}
reverse(op1.begin(), op1.end());
for(int i = 0; i < n; i += 2) {
op.push_back(op1[i] * 2 + op1[i + 1]);
}
int ans = getans(0) - 1;
int sufz = 0;
for(int i = op.size() - 1; op[i] == 0; i--) sufz++;
if(k > sufz + 1 && sufz < op.size()) ans = -1;
else ans = (ans + S(k)) % p;
cout << ans << "\n";
}
signed main() {
// freopen("data.in", "r", stdin);
// freopen("data.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
fc[0] = 1; inv3 = powe(3, p - 2);
for(int i = 1; i < N; i++) {
fc[i] = fc[i - 1] * 4 % p;
}
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: 6ms
memory: 11488kb
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: 7ms
memory: 12188kb
input:
1 0 0 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 7ms
memory: 12348kb
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 44 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 63 42 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:
wrong answer 14th numbers differ - expected: '12', found: '44'