QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#281434 | #7789. Outro: True Love Waits | ucup-team197# | WA | 0ms | 3876kb | C++14 | 1.1kb | 2023-12-10 05:03:43 | 2023-12-10 05:03:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const ll mod=1e9+7;
int n;
ll dp[10000001];
ll pw(ll x,ll y){
if(y==0) return 1;
if(y%2) return x*pw(x,y-1)%mod;
ll res=pw(x,y/2);
return res*res%mod;
}
void solve(){
string s,t;ll k;
cin >> s >> t >> k;
reverse(s.begin(),s.end());
reverse(t.begin(),t.end());
int n=max(s.size(),t.size());
if(n%2) ++n;
s.resize(n,'0');
t.resize(n,'0');
bool ugly=true;
for(int i=0; i<n ;i++){
s[i]^=t[i]%2;
if(s[i]%2) ugly=false;
}
if(ugly){
ll res=(pw(4,k)+mod-4)%mod;
res=res*pw(3,mod-2)%mod;
cout << res << '\n';
return;
}
n/=2;
int m=0;
while(s[2*m]=='0' && s[2*m+1]=='0') m++;
if(k>m+1){
cout << "-1\n";
return;
}
dp[0]=0;
for(int i=1; i<=2*n ;i++) dp[i]=(dp[i-1]*4+4)%mod;
ll base=0;
for(int i=m; i<n ;i++){
int frog=(s[2*m+1]-'0')*2+(s[2*m]-'0');
if(frog>=2) frog^=1;
base=(base+frog*(dp[i]+1))%mod;
}
ll ans=(base+dp[k-1])%mod;
cout << ans << '\n';
}
int main(){
ios::sync_with_stdio(false);
int t;cin >> t;while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
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: 3612kb
input:
1 0 0 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3876kb
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 54 27 54 78 54 81 81 27 81 81 81 27 12 81 52 27 18 81 27 27 81 54 27 54 27 54 81 81 81 78 81 81 78 54 54 27 78 81 54 81 42 27 54 27 0 63 18 81 15 10 27 54 81 27 54 81 81 54 52 21 81 54 27 21 26 54 54 42 81 27 54 54 81 81 81 81 54 81 54 81 27 54 26 81 81 27 81 81 26 27 27 27 27 81 27 12 26 42 54
result:
wrong answer 2nd numbers differ - expected: '59', found: '54'