QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#250072#7620. Yet Another Subsequence Problemucup-team2307#WA 0ms3860kbC++202.1kb2023-11-12 21:07:342023-11-12 21:07:35

Judging History

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

  • [2023-11-12 21:07:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3860kb
  • [2023-11-12 21:07:34]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define int ll

const int MOD=998244353;

#if 1
using row=array<int,3>;
using matr=array<row,3>;
const matr ONE={
    row{1,0,0},
    row{0,1,0},
    row{0,0,1}
};
matr mul(matr l,matr r)
{
    matr res{};
    for (int i = 0; i < 3; ++i)
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 3; k++)
                res[i][j] += l[i][k] * r[k][j];
            res[i][j]%=MOD;
        }
    return res;
}
const matr X={
    row{1,0,0},
    row{1,1,0},
    row{1,0,1}
};
const matr Y={
    row{1,1,0},
    row{0,1,0},
    row{0,1,1}
};
auto ret(matr res)
{
    return (res[2][0]+res[2][1]+1)%MOD;
}
#else
using matr=string;
const matr ONE;
matr mul(const matr& l,const matr& r)
{
    return l+r;
}
const matr X="1";
const matr Y="0";
auto ret(matr res)
{
    return res;
}
#endif

matr pow(matr x,int y)
{
    matr res=ONE;
    while(y)
    {
        if(y&1)
            res=mul(res,x);
        y>>=1;
        x=mul(x,x);
    }
    return res;
}

matr rec(int a, int b, matr x, matr y)
{
    while(a>1||b>1)
    {
//        cout << a << " " << b << " " << x << " " << y << "\n";
        matr xx=mul(pow(x, b / a - 1),y);
        matr yy=mul(x,xx);
        tie(a, b, y, x)=tuple(a - b % a, a, xx, yy);
    }
    return y;
}

auto solve(int a,int b)
{
    int g=__gcd(a,b);
    matr res=rec(a/g,b/g,Y,mul(X,Y));
    res=pow(res,g);
    return ret(res);
}

std::string gen_string(int64_t a, int64_t b) {
    std::string res;
    int64_t ia = 0, ib = 0;
    while (ia + ib < a + b) {
        if ((__int128)ia * b <= (__int128)ib * a) {
            res += '0';
            ia++;
        } else {
            res += '1';
            ib++;
        }
    }
    reverse(res.begin(),res.end());
    return res;
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin>>t;
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        cout<<gen_string(a,b)<<"\n";
        cout<<solve(min(a,b),max(a,b))<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
1 1
3 5
4 7
8 20
4 10
27 21

output:

10
4
10110110
78
10110110110
294
1101110110111011011101101110
236989
11011101101110
735
010101001010101001010100101010100101010010101010
667131122

result:

wrong answer 1st numbers differ - expected: '4', found: '10'