結果

問題 No.1632 Sorting Integers (GCD of M)
ユーザー kotatsugamekotatsugame
提出日時 2021-07-30 21:28:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 3,379 bytes
コンパイル時間 961 ms
コンパイル使用メモリ 78,424 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 16:15:16
合計ジャッジ時間 2,546 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 18 ms
4,348 KB
testcase_05 AC 18 ms
4,348 KB
testcase_06 AC 17 ms
4,348 KB
testcase_07 AC 17 ms
4,348 KB
testcase_08 AC 18 ms
4,348 KB
testcase_09 AC 17 ms
4,348 KB
testcase_10 AC 17 ms
4,348 KB
testcase_11 AC 17 ms
4,348 KB
testcase_12 AC 19 ms
4,348 KB
testcase_13 AC 19 ms
4,348 KB
testcase_14 AC 19 ms
4,348 KB
testcase_15 AC 17 ms
4,348 KB
testcase_16 AC 13 ms
4,348 KB
testcase_17 AC 13 ms
4,348 KB
testcase_18 AC 15 ms
4,348 KB
testcase_19 AC 11 ms
4,348 KB
testcase_20 AC 13 ms
4,348 KB
testcase_21 AC 11 ms
4,348 KB
testcase_22 AC 13 ms
4,348 KB
testcase_23 AC 13 ms
4,348 KB
testcase_24 AC 13 ms
4,348 KB
testcase_25 AC 13 ms
4,348 KB
testcase_26 AC 12 ms
4,348 KB
testcase_27 AC 6 ms
4,348 KB
testcase_28 AC 5 ms
4,348 KB
testcase_29 AC 5 ms
4,348 KB
testcase_30 AC 6 ms
4,348 KB
testcase_31 AC 6 ms
4,348 KB
testcase_32 AC 5 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 3 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 3 ms
4,348 KB
testcase_39 AC 3 ms
4,348 KB
testcase_40 AC 4 ms
4,348 KB
testcase_41 AC 4 ms
4,348 KB
testcase_42 AC 3 ms
4,348 KB
testcase_43 AC 4 ms
4,348 KB
testcase_44 AC 4 ms
4,348 KB
testcase_45 AC 3 ms
4,348 KB
testcase_46 AC 4 ms
4,348 KB
testcase_47 AC 3 ms
4,348 KB
testcase_48 AC 3 ms
4,348 KB
testcase_49 AC 2 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
testcase_52 AC 2 ms
4,348 KB
testcase_53 AC 2 ms
4,348 KB
testcase_54 AC 2 ms
4,348 KB
testcase_55 AC 2 ms
4,348 KB
testcase_56 AC 2 ms
4,348 KB
testcase_57 AC 2 ms
4,348 KB
testcase_58 AC 2 ms
4,348 KB
testcase_59 AC 2 ms
4,348 KB
testcase_60 AC 1 ms
4,348 KB
testcase_61 AC 1 ms
4,348 KB
testcase_62 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
a.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]

ソースコード

diff #

#line 1 "a.cpp"
#include<iostream>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint1000000007;
#line 1 "/home/kotatsugame/library/math/matrix.cpp"
#include<vector>
#include<cassert>
template<typename T>
struct Matrix{
	vector<vector<T> >dat;
	int N,M;//N x M matrix
	Matrix(){}
	Matrix(int N_):Matrix(N_,N_){}
	Matrix(int N_,int M_):N(N_),M(M_),dat(N_,vector<T>(M_)){}
	vector<T>&operator[](int i){return dat[i];}
	const vector<T>&operator[](int i)const{return dat[i];}
	static Matrix eye(int N)
	{
		Matrix res(N);
		for(int i=0;i<N;i++)res[i][i]=1;
		return res;
	}
	Matrix operator+(const Matrix&A)const
	{
		assert(N==A.N&&M==A.M);
		Matrix res(N,M);
		for(int i=0;i<N;i++)for(int j=0;j<M;j++)
			res[i][j]=dat[i][j]+A[i][j];
		return res;
	}
	Matrix operator-(const Matrix&A)const
	{
		assert(N==A.N&&M==A.M);
		Matrix res(N,M);
		for(int i=0;i<N;i++)for(int j=0;j<M;j++)
			res[i][j]=dat[i][j]-A[i][j];
		return res;
	}
	Matrix operator*(const Matrix&A)const
	{
		assert(M==A.N);
		Matrix res(N,A.M);
		for(int i=0;i<N;i++)for(int k=0;k<M;k++)for(int j=0;j<A.M;j++)
			res[i][j]+=dat[i][k]*A[k][j];
		return res;
	}
	Matrix pow(long long n)const
	{
		assert(N==M);
		Matrix a=*this,res=eye(N);
		for(;n;a=a*a,n>>=1)if(n&1)res=res*a;
		return res;
	}
	template<typename U>
	Matrix operator+(const U&A)const
	{
		Matrix res(N,M);
		for(int i=0;i<N;i++)for(int j=0;j<M;j++)
			res[i][j]=dat[i][j]+A;
		return res;
	}
	template<typename U>
	Matrix operator-(const U&A)const
	{
		Matrix res(N,M);
		for(int i=0;i<N;i++)for(int j=0;j<M;j++)
			res[i][j]=dat[i][j]-A;
		return res;
	}
	template<typename U>
	Matrix operator*(const U&A)const
	{
		Matrix res(N,M);
		for(int i=0;i<N;i++)for(int j=0;j<M;j++)
			res[i][j]=dat[i][j]*A;
		return res;
	}
	T det()const
	{
		assert(N==M);
		Matrix A=*this;
		T ret=1;
		for(int j=0;j<N;j++)
		{
			int id=-1;
			for(int i=j;i<N;i++)
			{
				if(A[i][j]!=0)
				{
					id=i;
					break;
				}
			}
			if(id==-1)return T(0);
			if(id!=j)
			{
				A[j].swap(A[id]);
				ret=-ret;
			}
			ret*=A[j][j];
			{
				const T a=1/A[j][j];
				for(int k=j+1;k<N;k++)A[j][k]*=a;
			}
			for(int i=j+1;i<N;i++)
			{
				const T a=A[i][j];
				for(int k=j+1;k<N;k++)A[i][k]-=A[j][k]*a;
			}
		}
		return ret;
	}
	int elimination()
	{
		int ret=0;
		for(int j=0;j<M;j++)
		{
			int id=-1;
			for(int i=ret;i<N;i++)
			{
				if(dat[i][j]!=0)
				{
					id=i;
					break;
				}
			}
			if(id==-1)continue;
			if(id!=ret)dat[ret].swap(dat[id]);
			{
				const T a=1/dat[ret][j];
				for(int k=j;k<M;k++)dat[ret][k]*=a;
			}
			for(int i=0;i<N;i++)
			{
				if(i==ret)continue;
				const T a=dat[i][j];
				for(int k=j;k<M;k++)dat[i][k]-=dat[ret][k]*a;
			}
			ret++;
		}
		return ret;
	}
};
#line 6 "a.cpp"
using mat=Matrix<int>;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int N;
int C[10];
main()
{
	cin>>N;
	for(int i=1;i<=9;i++)cin>>C[i];
	for(int i=1;i<=9;i++)if(C[i]==N)
	{
		mint M=mint(10).pow(N)-1;
		M/=9;
		M*=i;
		cout<<M.val()<<endl;
		return 0;
	}
	int g=0;
	for(int i=1;i<=9;i++)if(C[i])for(int j=i+1;j<=9;j++)if(C[j])
	{
		int c=j-i;
		g=gcd(g,c);
	}
	g*=9;
	for(int i=g;i>=1;i--)if(g%i==0)
	{
		mat E(i,1);
		E[0][0]=1;
		for(int j=1;j<=9;j++)if(C[j]>0)
		{
			mat A(i,i);
			for(int k=0;k<i;k++)
			{
				A[(k*10+j)%i][k]=1;
			}
			E=A.pow(C[j])*E;
		}
		if(E[0][0])
		{
			cout<<i<<endl;
			return 0;
		}
	}
}
0