QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#623681#7789. Outro: True Love Waitskans2298WA 0ms12528kbC++176.3kb2024-10-09 13:41:522024-10-09 13:42:00

Judging History

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

  • [2024-10-09 13:42:00]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:12528kb
  • [2024-10-09 13:41:52]
  • 提交

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;
     if (ablemove>=k)
          {
          ans=(ans-1+MOD)%MOD;
          if (k>1)
               {
               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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 12528kb

input:

4
1 10 1
1 10 2
100 0 2
11 11 3

output:

2
-1
5
20

result:

wrong answer 3rd numbers differ - expected: '9', found: '5'