QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#258571 | #7620. Yet Another Subsequence Problem | ucup-team2580 | WA | 1ms | 3412kb | C++20 | 1.9kb | 2023-11-19 20:18:28 | 2023-11-19 20:18:29 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
const ll mod=998244353;
struct Matrix
{
ll val[3][3];
Matrix(vector<ll> vec)
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
val[i][j]=vec[i*3+j];
}
Matrix(){}
ll* operator [](int x){return val[x];}
friend Matrix operator *(Matrix a,Matrix b)
{
Matrix ret;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
ret[i][j]=0;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
for(int k=0;k<3;k++)
ret[i][j]=(ret[i][j]+a[i][k]*b[k][j])%mod;
return ret;
}
};
Matrix ksm(Matrix a,ll b)
{
Matrix ans({1,0,0,0,1,0,0,0,1});
while(b)
{
if(b&1) ans=ans*a;
a=a*a;
b>>=1;
}
return ans;
}
Matrix F(ll p,ll q,ll r,ll M,Matrix U,Matrix R)
{
if(!M) return Matrix({1,0,0,0,1,0,0,0,1});
if((longer)(p*M+r)<q) return ksm(R,M);
if(p>=q) return F(p%q,q,r,M,U,ksm(U,p/q)*R);
return ksm(R,(q-r-1)/p)*U*F(q,p,(q-r-1)%p,(longer)(p*M+r)/q-1,R,U)*ksm(R,M-(longer(p*M-1-(p*M+r)%q)/p));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
ll A,B;
cin>>A>>B;
Matrix U=Matrix({1,0,0,1,1,0,1,0,1}),R=Matrix({1,1,0,0,1,0,0,1,1});
Matrix ans=U*R*F(A,B,0,B-1,U,R);
ll tot=A+B-(B-1)-2-(B-1)*A/B;
ans=ans*ksm(U,tot);
cout<<(ans[2][0]+ans[2][1]+ans[2][2])%mod<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3412kb
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: 3408kb
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 969409814 786938578 917438628 24364208 109943645 531997235 388166140 555365227 757266986
result:
wrong answer 10th numbers differ - expected: '627433544', found: '969409814'