QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#765430#9479. And DNANahidameowCompile Error//C++202.2kb2024-11-20 14:17:392024-11-20 14:17:40

Judging History

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

  • [2024-11-20 14:17:40]
  • 评测
  • [2024-11-20 14:17:39]
  • 提交

answer

#include<bits/stdc++.h>
#define pd push_back
#define all(A) A.begin(),A.end()
#define lb lower_bound
#define ve std::vector
typedef long long ll;
typedef long long ll;
typedef __int128 Int;
typedef unsigned long long ul;
typedef long double LD;
bool FileIfstream(std::string name){
	std::ifstream f(name.c_str());
	return f.good();
}
namespace Math{
	ll QP(ll x,ll y,ll mod){ll ans=1;for(;y;y>>=1,x=x*x%mod)if(y&1)ans=ans*x%mod;return ans;}
	ll inv(ll x,ll mod){return QP(x,mod-2,mod);}
}
const int N=2e5+10;
const int mod=998244353;
template<int n,int m>
struct Matrix{
	int C[n][m];
	Matrix<n,m>(){memset(C,0,sizeof(C));}
	Matrix<n,m>(ve<ve<int>>v){
		for(int i=0;i<n;i++)
			for(int j=0;j<=m;j++)
				C[i][j]=v[i][j];
	}
	auto operator [](int i)const{return C[i];};
	auto& operator [](int i){return C[i];}
	template<int k>
	Matrix<n,k> operator *(Matrix<m,k>P){
		Matrix<n,k> ans;
		for(int i=0;i<n;i++)
			for(int j=0;j<k;j++)
				for(int c=0;c<m;c++)
					ans[i][j]=(ans[i][j]+1ll*C[i][c]*P[c][j]%mod)%mod;
		return ans;	
	}
	Matrix<n,n> operator ^(ll y){
		Matrix<n,n>ans;assert(n==m);
		for(int i=0;i<n;i++)ans[i][i]=1;
		Matrix<n,n>x=(*this);
		for(;y;x=x*x,y>>=1)
			if(y&1)ans=ans*x;
		return ans;
	} 
};
void solve(){
	//don't forget to open long long
	int n,m;std::cin>>n>>m;
	Matrix<3,3>Base({{0,1,1},
					 {1,0,0},
					 {0,1,0}});
	Matrix<3,3>V=Base^n;
	std::map<int,int>mp;
	auto dfs=[&](int x,auto self)->int{
		if(!x)return 1;if(mp.count(x))return mp[x];
		int &p=mp[x];
		if(x==1)return p=(0ll+V[0][0]+V[1][1]+V[2][2])%mod;
		if(x&1^1)return p=(self(x/2,self)+self(x/2-1,self))%mod;
		return p=1ll*self(x/2,self)*(0ll+V[0][0]+V[1][1]+V[2][2])%mod;
	};
	std::cout<<dfs(m,dfs)<<'\n';
}
int main(){
#ifndef ONLINE_JUDGE
	if(!FileIfstream("IO.in")){
		freopen("IO.in","w",stdout);
		return 0;
	}
	freopen("IO.in","r",stdin);
	freopen("IO.out","w",stdout);
#endif
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
	int T=1;
	//std::cin>>T;
	while(T--)solve();

#ifndef ONLINE_JUDGE
	std::cerr<<std::fixed<<std::setprecision(10)<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
#endif

	return 0;
}






詳細信息

answer.code:24:21: error: expected unqualified-id before ‘)’ token
   24 |         Matrix<n,m>(){memset(C,0,sizeof(C));}
      |                     ^
answer.code:25:32: error: invalid declarator before ‘v’
   25 |         Matrix<n,m>(ve<ve<int>>v){
      |                                ^
answer.code:25:32: error: expected ‘)’ before ‘v’
   25 |         Matrix<n,m>(ve<ve<int>>v){
      |                    ~           ^
      |                                )