QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#250100 | #7620. Yet Another Subsequence Problem | ucup-team2307 | WA | 1ms | 3620kb | C++20 | 2.4kb | 2023-11-12 21:22:44 | 2023-11-12 21:22:45 |
Judging History
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++)
{
res[i][j]=((ll)l[i][0]*r[0][j]+(ll)l[i][1]*r[1][j]+(ll)l[i][2]*r[2][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}
};
const matr invX={
row{1,0,0},
row{MOD-1,1,0},
row{MOD-1,0,1}
};
const matr invY={
row{1,MOD-1,0},
row{0,1,0},
row{0,MOD-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);
bool sw=a>b;
if(sw)
swap(a,b);
matr res=rec(a/g,b/g,Y,mul(X,Y));
if(!sw)
{
res=mul(res,invY);
res=mul(res,invX);
res=mul(res,Y);
res=mul(res,X);
}
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(a,b)<<"\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
input:
6 1 1 3 5 4 7 8 20 4 10 27 21
output:
4 70 264 196417 609 667131122
result:
ok 6 numbers
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3600kb
input:
18 5 9 23 30 820 483 5739 9232 86494 55350 606 13336 2768848 1124639 47995594 66053082 1069395 7177 7801842511 4390103762 47882886553 82678306054 193410894 6189355686 51594638 19992922190 59 110 422735115778072 658356435030265 9125338158530266 5328357177709583 60743352262021049 95595862538791630 629...
output:
988 220693002 133474535 202371605 778839228 282057418 935955056 943144752 409056617 234547032 234547032 234547032 234547032 234547032 234547032 234547032 234547032 234547032
result:
wrong answer 10th numbers differ - expected: '627433544', found: '234547032'