QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#661213 | #7789. Outro: True Love Waits | ruoye123456 | WA | 5ms | 7576kb | C++20 | 2.2kb | 2024-10-20 15:17:51 | 2024-10-20 15:17:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
vector<int> vx;
inline void divide() {sort(vx.begin(),vx.end());vx.erase(unique(vx.begin(),vx.end()),vx.end());}
//inline int mp(int x) {return upper_bound(vx.begin(),vx.end(),x)-vx.begin();}
inline int log_2(int x) {return 31-__builtin_clz(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int lowbit(int x) {return x&-x;}
inline ll Lsqrt(ll x) { ll L = 1,R = 2e9;while(L + 1 < R){ll M = (L+R)/2;if(M*M <= x) L = M;else R = M;}return L;}
int turn[4] = {0,1,3,2};
const int N = 1e6, p = 1e9+7;
int POW4[N+10];
ll quick_pow(ll a,int b)
{
a%=p;
ll ans=1;
for(;b;b>>=1)
{
if(b&1) ans=ans*a%p;
a=a*a%p;
}
return ans;
}
ll inv(ll x)
{
return quick_pow(x,p-2);
}
void solve()
{
string s,t;
int k;
cin>>s>>t>>k;
int n = s.size(), m = t.size();
reverse(s.begin(),s.end());
reverse(t.begin(),t.end());
int MAX = max(n,m);
MAX += (MAX&1);
vector<int> S(MAX),T(MAX),X(MAX/2);
for(int i=0;i<n;++i) S[i] = s[i]-'0';
for(int i=0;i<m;++i) T[i] = t[i]-'0';
for(int i=0;i<MAX;i+=2) X[i/2] = turn[(S[i]^T[i])+(S[i+1]^T[i+1])*2];
if(*max_element(X.begin(),X.end()) == 0)
{
int inv3 = inv(3);
ll res = (ll)(quick_pow(4,k) - 4 + p)*inv(3) % p;
cout<<res<<'\n';
}
else if(k > 2 || k == 2 && X[0] != 0) {cout<<"-1\n";return ;}
else
{
auto cal = [&]()->ll
{
ll res = 0;
for(int i=0;i<MAX/2;++i)
{
res += (ll)POW4[i]*X[i];
res += i*X[i];
res %= p;
}
return res;
};
cout<< (cal() + (ll)(k-1) * 4) % p<<'\n';
}
}
int main()
{
POW4[0] = 1;
for(int i=1;i<=(int)1e6;++i)
{
POW4[i] = (ll)POW4[i-1] * 4 % p;
}
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin>>T;
while(T--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 7576kb
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: 7476kb
input:
1 0 0 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 7488kb
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:
69 53 60 61 15 35 36 3 29 54 3 26 60 12 39 46 34 3 26 55 19 36 48 60 56 24 30 67 31 18 51 13 72 15 20 61 60 33 18 20 26 36 60 48 6 0 54 3 26 15 10 16 71 21 34 53 62 13 20 28 18 31 20 42 18 41 7 38 36 3 34 66 53 26 49 36 26 25 26 61 49 16 48 41 21 18 70 54 8 23 55 52 29 6 8 34 2 59 36 38
result:
wrong answer 1st numbers differ - expected: '78', found: '69'