Submission #41183138
Source Code Expand
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
const int mod=998244353;
void add(ll& x,ll y){x=(x+y)%mod;}
void sub(ll& x,ll y){x=(x-y+mod)%mod;}
ll addv(ll x,ll y){return (x+y)%mod;}
ll subv(ll x,ll y){return (x-y+mod)%mod;}
ll mypow(ll a,ll n){
if(!n)return 1;
ll tmp=mypow(a,n/2);tmp=tmp*tmp%mod;
if(n&1)tmp=tmp*a%mod;return tmp;
}
ll myinv(ll a){return mypow(a,mod-2);}
const int MAXN=20,d6=myinv(6),V=1e9;
struct Mat{
ll a[MAXN][MAXN],n,m;
Mat(int n=0,int m=0){
memset(a,0,sizeof a);
this->n=n,this->m=m;
}
void operator=(const Mat& m2){
n=m2.n,m=m2.m;
rep(i,1,n)rep(j,1,m)a[i][j] = m2.a[i][j];
}
void solve(int x,int y){
if(x>n || y>=m)return;
int r=-1;
rep(i,x,n)if(a[i][y]){r=i;break;}
if(r==-1)return solve(x,y+1);
rep(i,1,m)swap(a[x][i],a[r][i]);
rep(i,x+1,n)if(a[i][y]){
ll k=a[i][y] * myinv(a[x][y])%mod;
rep(j,1,m)sub(a[i][j],a[x][j] * k%mod);
}
return solve(x+1,y+1);
}
void calc(ll* f){
per(i,n,1){
int r=-1;
rep(j,1,m-1)if(a[i][j]){r=j;break;}
if(r==-1)continue;
f[r-1] = a[i][m]*myinv(a[i][r])%mod;
per(j,i-1,1)if(a[j][r]){
sub(a[j][m],a[j][r]*f[r-1]%mod);
a[j][r]=0;
}
}
}
};
Mat operator*(const Mat x,const Mat y){
Mat z(x.n,y.m);
rep(i,1,x.n)rep(k,1,x.m)rep(j,1,y.m)add(z.a[i][j],x.a[i][k] * y.a[k][j]%mod);
return z;
}
Mat mypow(const Mat x,int n){
if(n==1)return x;
Mat tmp=mypow(x,n/2);tmp=tmp*tmp;
if(n&1)tmp=tmp*x;return tmp;
}
ll r;
typedef array<ll,2> pr;
pr calc(ll t){ //f = sum f*p g = sum (g+f)*p
ll f[10]={0},g[10]={0};
f[0] = 1;
rep(i,1,6){
rep(j,0,i-1)add(f[i],f[j]*d6%mod),add(g[i],(g[j]+f[j])*d6%mod);
}
if(t<=6)return {f[t],g[t]};
Mat v(1,12),a(12,12);
rep(i,1,6){
v.a[1][i] = f[i],v.a[1][6+i] = g[i];
if(i>1)a.a[i][i-1] = a.a[6+i][5+i] = 1;
a.a[i][6] = a.a[i][12] = a.a[i+6][12] = d6;
}
v=v*mypow(a,t-6);
return {v.a[1][6],v.a[1][12]};
}
pr calc(ll s,ll t){
ll f[10]={0},g[10]={0};
rep(i,0,t-s){
pr tmp=calc(s+i);
f[i] = tmp[0],g[i] = tmp[1];
}
t-=s;
per(i,t,1){
rep(j,0,i-1){
sub(f[i],f[j]*d6%mod);
sub(g[i],(g[j]+f[j])*d6%mod);
}
}
return {f[t],g[t]};
}
//
ll p[MAXN],g[MAXN][MAXN],a[MAXN],b[MAXN],ans;
int main(){
cin>>r;
rep(i,0,5)p[i] = calc(r,r+i)[0];
rep(i,0,5)rep(j,0,5)g[i][j] = calc(V-i,V-i+j)[0];
Mat ma(6,7),mb(6,7);
rep(i,0,5){
ma.a[i+1][7] = p[i];
ma.a[i+1][i+1] = 1;
rep(j,1,5)sub(ma.a[i+1][j+1],g[j][i]);
}
ma.solve(1,1);
ma.calc(a);
rep(i,0,5){
ll w=calc(r,r+i)[1];
add(ans,w);
}
rep(i,1,5)rep(j,0,5){
ll w=calc(V-i,V-i+j)[1];
add(ans,w*a[i]%mod);
}
cout<<ans<<endl;
return 0;
}
Submission Info
| Submission Time |
|
| Task |
Ex - Dice Sum Infinity |
| User |
Crying |
| Language |
C++ (GCC 9.2.1) |
| Score |
600 |
| Code Size |
3092 Byte |
| Status |
AC |
| Exec Time |
69 ms |
| Memory |
4120 KiB |
Compile Error
./Main.cpp: In function ‘ll mypow(ll, ll)’:
./Main.cpp:23:2: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
23 | if(n&1)tmp=tmp*a%mod;return tmp;
| ^~
./Main.cpp:23:23: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
23 | if(n&1)tmp=tmp*a%mod;return tmp;
| ^~~~~~
./Main.cpp: In function ‘Mat operator*(Mat, Mat)’:
./Main.cpp:69:9: warning: implicitly-declared ‘constexpr Mat::Mat(const Mat&)’ is deprecated [-Wdeprecated-copy]
69 | return z;
| ^
./Main.cpp:35:7: note: because ‘Mat’ has user-provided ‘void Mat::operator=(const Mat&)’
35 | void operator=(const Mat& m2){
| ^~~~~~~~
./Main.cpp: In function ‘Mat mypow(Mat, int)’:
./Main.cpp:72:17: warning: implicitly-declared ‘constexpr Mat::Mat(const Mat&)’ is deprecated [-Wdeprecated-copy]
72 | if(n==1)return x;
| ^
./Main.cpp:35:7: note: because ‘Mat’ has user-provided ‘void Mat::operator=(const Mat&)’
35 | void operator=(const Mat& m2){
| ^~~~~~~~
./Main.cpp:73:21: warning: implicitly-declared ‘constexpr Mat::Mat(const Mat&)’ is deprecated [-Wdeprecated-copy]
73 | Mat tmp=mypow(x,n/2);tmp=tmp*tmp;
| ^
./Main.cpp:35:7: note: because ‘Mat’ has user-provided ‘void Mat::operator=(const Mat&)’
35 | void operator=(const Mat& m2){
| ^~~~~~~~
./Main.cpp:71:21: note: initializing argument 1 of ‘Mat mypow(Mat, int)’
71 | Mat mypow(const Mat x,int n){
| ~~~~~~~~~~^
./Main.cpp:73:31: warning: implicitly-declared ‘constexpr Mat::Mat(const Mat&)’ is deprecated [-Wdeprecated-copy]
73 | Mat tmp=mypow(x,n/2);tmp=tmp*tmp;
| ^~~
./Main.cpp:35:7: note: because ‘Mat’ has user-provided ‘void Mat::operator=(const Mat&)’
35 | void operator=(const Mat& m2){
| ^~~~~~~~
./Main.cpp:66:25: note: initializing arg...
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
600 / 600 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt, 00_sample_01.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 01_edge_02.txt, 01_edge_03.txt, 01_edge_04.txt, 01_edge_05.txt, 01_edge_06.txt, 01_edge_07.txt, 01_edge_08.txt, 01_edge_09.txt, 01_edge_10.txt, 01_edge_11.txt, 01_edge_12.txt, 01_edge_13.txt, 01_edge_14.txt, 01_edge_15.txt, 01_edge_16.txt, 01_edge_17.txt, 01_edge_18.txt, 01_edge_19.txt, 01_edge_20.txt, 01_edge_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt, 02_random_25.txt, 02_random_26.txt, 02_random_27.txt, 02_random_28.txt, 02_random_29.txt, 02_random_30.txt, 02_random_31.txt, 02_random_32.txt, 02_random_33.txt, 02_random_34.txt, 02_random_35.txt, 02_random_36.txt, 02_random_37.txt, 02_random_38.txt, 02_random_39.txt, 02_random_40.txt, 02_random_41.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
60 ms |
3904 KiB |
| 00_sample_01.txt |
AC |
67 ms |
3912 KiB |
| 01_edge_02.txt |
AC |
55 ms |
4008 KiB |
| 01_edge_03.txt |
AC |
56 ms |
4012 KiB |
| 01_edge_04.txt |
AC |
56 ms |
4068 KiB |
| 01_edge_05.txt |
AC |
55 ms |
3864 KiB |
| 01_edge_06.txt |
AC |
56 ms |
4064 KiB |
| 01_edge_07.txt |
AC |
57 ms |
4016 KiB |
| 01_edge_08.txt |
AC |
57 ms |
3908 KiB |
| 01_edge_09.txt |
AC |
56 ms |
4120 KiB |
| 01_edge_10.txt |
AC |
55 ms |
4048 KiB |
| 01_edge_11.txt |
AC |
57 ms |
3900 KiB |
| 01_edge_12.txt |
AC |
64 ms |
3860 KiB |
| 01_edge_13.txt |
AC |
63 ms |
4004 KiB |
| 01_edge_14.txt |
AC |
68 ms |
4004 KiB |
| 01_edge_15.txt |
AC |
64 ms |
4012 KiB |
| 01_edge_16.txt |
AC |
65 ms |
4060 KiB |
| 01_edge_17.txt |
AC |
64 ms |
4016 KiB |
| 01_edge_18.txt |
AC |
64 ms |
4060 KiB |
| 01_edge_19.txt |
AC |
64 ms |
4064 KiB |
| 01_edge_20.txt |
AC |
64 ms |
3912 KiB |
| 01_edge_21.txt |
AC |
69 ms |
4008 KiB |
| 02_random_22.txt |
AC |
62 ms |
4064 KiB |
| 02_random_23.txt |
AC |
63 ms |
4012 KiB |
| 02_random_24.txt |
AC |
63 ms |
4064 KiB |
| 02_random_25.txt |
AC |
63 ms |
4044 KiB |
| 02_random_26.txt |
AC |
65 ms |
4092 KiB |
| 02_random_27.txt |
AC |
63 ms |
4052 KiB |
| 02_random_28.txt |
AC |
63 ms |
3900 KiB |
| 02_random_29.txt |
AC |
62 ms |
4052 KiB |
| 02_random_30.txt |
AC |
62 ms |
3908 KiB |
| 02_random_31.txt |
AC |
62 ms |
4040 KiB |
| 02_random_32.txt |
AC |
63 ms |
4060 KiB |
| 02_random_33.txt |
AC |
64 ms |
4016 KiB |
| 02_random_34.txt |
AC |
63 ms |
3864 KiB |
| 02_random_35.txt |
AC |
64 ms |
4008 KiB |
| 02_random_36.txt |
AC |
63 ms |
3916 KiB |
| 02_random_37.txt |
AC |
63 ms |
3900 KiB |
| 02_random_38.txt |
AC |
63 ms |
4012 KiB |
| 02_random_39.txt |
AC |
64 ms |
4048 KiB |
| 02_random_40.txt |
AC |
63 ms |
4008 KiB |
| 02_random_41.txt |
AC |
64 ms |
4056 KiB |