QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#623765 | #7789. Outro: True Love Waits | kans2298 | WA | 4ms | 12584kb | C++17 | 6.5kb | 2024-10-09 13:56:07 | 2024-10-09 13:56:25 |
Judging History
answer
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<utility>
#define MOD 1000000007
using namespace std;
using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;
i64 f[1000001],f2[1000001],f3[1000001],f4[1000001];
void pre()
{
f[1]=1;
i64 st1=1,st2=4;
for (int i=2;i<=100000;i+=2)
{
f[i]=(f[i-1]+st1)%MOD;
st1=(st1+st2)%MOD;
st2=st2*4%MOD;
f[i+1]=(f[i]+st1)%MOD;
}
f2[1]=1;
st1=2,st2=1;
for (int i=2;i<=100000;++i)
{
f2[i]=(f2[i-1]+st1)%MOD;
st2=st2*4%MOD;
st1=(st1+st2)%MOD;
}
f3[1]=2;
st1=10,st2=8;
for (int i=2;i<=100000;++i)
{
f3[i]=(f3[i-1]+st1)%MOD;
st2=st2*4%MOD;
st1=(st1+st2)%MOD;
}
f4[1]=4;
st1=4;
for (int i=2;i<=100000;++i)
{
st1=st1*4%MOD;
f4[i]=(f4[i-1]+st1)%MOD;
}
}
pair<i64,int> get_id(int l,int r)
{
l=r-(l-1); //l is the num of 1
i64 id=f[r]+1;
if (l%2!=r%2)
{
int step=(r-1-l)/2+1;
return {(id+f2[step])%MOD,step};
}
else
{
int step=(r-l)/2;
return {(id-f3[step]+MOD)%MOD,step+1};
}
}
template <class T>
constexpr T power(T a, i64 b)
{
T res{1};
for (; b; b /= 2, a *= a)
{
if (b % 2)
{
res *= a;
}
}
return res;
}
constexpr i64 mul(i64 a, i64 b, i64 p)
{
i64 res = a * b - i64(1.L * a * b / p) * p;
res %= p;
if (res < 0)
{
res += p;
}
return res;
}
template <i64 P>
struct MInt
{
i64 x;
constexpr MInt() : x{0} {}
constexpr MInt(i64 x) : x{norm(x % getMod())} {}
static i64 Mod;
constexpr static i64 getMod()
{
if (P > 0)
{
return P;
}
else
{
return Mod;
}
}
constexpr static void setMod(i64 Mod_)
{
Mod = Mod_;
}
constexpr i64 norm(i64 x) const
{
if (x < 0)
{
x += getMod();
}
if (x >= getMod())
{
x -= getMod();
}
return x;
}
constexpr i64 val() const
{
return x;
}
constexpr MInt operator-() const
{
MInt res;
res.x = norm(getMod() - x);
return res;
}
constexpr MInt inv() const
{
return power(*this, getMod() - 2);
}
constexpr MInt &operator*=(MInt rhs) &
{
if (getMod() < (1ULL << 31))
{
x = x * rhs.x % int(getMod());
}
else
{
x = mul(x, rhs.x, getMod());
}
return *this;
}
constexpr MInt &operator+=(MInt rhs) &
{
x = norm(x + rhs.x);
return *this;
}
constexpr MInt &operator-=(MInt rhs) &
{
x = norm(x - rhs.x);
return *this;
}
constexpr MInt &operator/=(MInt rhs) &
{
return *this *= rhs.inv();
}
friend constexpr MInt operator*(MInt lhs, MInt rhs)
{
MInt res = lhs;
res *= rhs;
return res;
}
friend constexpr MInt operator+(MInt lhs, MInt rhs)
{
MInt res = lhs;
res += rhs;
return res;
}
friend constexpr MInt operator-(MInt lhs, MInt rhs)
{
MInt res = lhs;
res -= rhs;
return res;
}
friend constexpr MInt operator/(MInt lhs, MInt rhs)
{
MInt res = lhs;
res /= rhs;
return res;
}
friend constexpr std::istream &operator>>(std::istream &is, MInt &a)
{
i64 v;
is >> v;
a = MInt(v);
return is;
}
friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a)
{
return os << a.val();
}
friend constexpr bool operator==(MInt lhs, MInt rhs)
{
return lhs.val() == rhs.val();
}
friend constexpr bool operator!=(MInt lhs, MInt rhs)
{
return lhs.val() != rhs.val();
}
friend constexpr bool operator<(MInt lhs, MInt rhs)
{
return lhs.val() < rhs.val();
}
};
template <>
i64 MInt<0>::Mod = 1000000007;
constexpr int P = 1000000007;
using Z = MInt<0>;
bool all0(const vector<int> &t)
{
for (auto x:t)
if (x!=0) return false;
return true;
}
int main()
{
int t,ti;
//freopen("input.in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);
pre();
cin>>t;
for (ti=1;ti<=t;++ti)
{
string s,t;
int k,n;
cin>>s>>t;
cin>>k;
vector<int> t2;
int t1=((int)(s.length()))-t.length();
t1=abs(t1);
if (t1>0)
{
string zero(t1,'0');
if (s.length()>t.length()) t=zero+t;
else s=zero+s;
}
n=s.length();
t2.resize(n);
for (int i=0;i<n;++i)
t2[i]=(s[i]-'0') xor (t[i]-'0');
reverse(t2.begin(),t2.end());
if (all0(t2))
{
Z ans=0;
ans=power(4,k-1)-1;
ans=4*ans/3;
cout<<ans<<"\n";
continue;
}
int lst=-1;
i64 ans=1,ablemove=2333333333ll;
for (int i=n-1;i>=0;--i)
{
if (t2[i])
{
if (lst==-1) lst=i;
}
else if (lst!=-1)
{
auto [x,y]=get_id(i+2,lst+1);
ans=(ans+x-1)%MOD;
ablemove=min(ablemove,(long long)y);
lst=-1;
}
}
if (lst!=-1)
{
auto [x,y]=get_id(1,lst+1);
ans=(ans+x-1)%MOD;
ablemove=min(ablemove,(long long)y);
}
//ans=(ans+f4[k-1])%MOD;
ablemove=0;
for (int i=0;i<n;++i)
if (t2[i]!=0)
{
ablemove=i;
break;
}
ablemove+=1;
if (ablemove>=k)
{
ans=(ans-1+MOD)%MOD;
if (k>1)
{
Z kk=0;
kk=power(4,k-1)-1;
kk=4*kk/3;
cout<<kk+ans<<"\n";
}
else cout<<ans<<"\n";
}
else cout<<"-1\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 10488kb
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: 12144kb
input:
1 0 0 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 12560kb
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 12 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 15 10 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:
ok 100 numbers
Test #4:
score: -100
Wrong Answer
time: 4ms
memory: 12584kb
input:
100 10011111 111 2 1011101100 1000000100 1 100011111 1001001111 1 1001100101 1100100001 1 10101000 10000100 1 1011110101 100011101 1 110100001 111011010 1 1101001100 1111101101 1 1001101 11011010 1 1101110110 1101011000 1 110011001 1100001111 2 1001111001 1011001111 1 1001110 1101110100 2 1110110100...
output:
295 248 788 431 73 930 144 319 283 76 1311 305 746 -1 86 -1 312 293 1293 433 1179 0 884 963 1215 576 -1 1132 499 811 864 949 1322 406 526 862 -1 447 1203 1238 873 -1 -1 1131 1108 438 134 359 80 740 1057 752 31 950 1093 1261 650 235 996 876 504 925 1344 450 1010 273 411 1144 1041 717 949 164 -1 11 79...
result:
wrong answer 11th numbers differ - expected: '-1', found: '1311'