提出 #69684097


ソースコード 拡げる

#include<bits/extc++.h>
//#define ONLINE_JUDGE
#define _INT_TO_LL
#define _CLOSE_SYNC
//#define _USE_FREOPEN
#if 1
using namespace std;
using namespace chrono;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using ui32=unsigned int;
using i64=long long;
using ui64=unsigned long long;
using i128=__int128;
using ui128=unsigned __int128;
using f64=double;
using f128=long double;
template<typename _Type> _Type __lcm(_Type a,_Type b){
	return a/__gcd(a,b)*b;
}
template<typename _Type> string yesno(_Type a,int b=1){
	return a?(b&2?"YES":b&1?"Yes":"yes"):(b&2?"NO":b&1?"No":"no");
}
template<typename Array,typename _Type> void mem(Array &arr,const _Type &value){
	typename remove_all_extents<Array>::type typedef ElementType;
	fill_n(reinterpret_cast<ElementType*>(&arr),sizeof(arr)/sizeof(ElementType),static_cast<ElementType>(value));
}
template<typename Array> void clr(Array &arr){
	typename remove_all_extents<Array>::type typedef ElementType;
	mem(arr,ElementType(0));
}
template<typename Array> void neg(Array &arr){
	typename remove_all_extents<Array>::type typedef ElementType;
	mem(arr,ElementType(-1));
}
template<typename Array> void fmax(Array &arr){
	typename remove_all_extents<Array>::type typedef ElementType;
	mem(arr,numeric_limits<ElementType>::max());
}
template<typename Array> void fmax_s(Array &arr){
	typename remove_all_extents<Array>::type typedef ElementType;
	mem(arr,numeric_limits<ElementType>::max()/2);
}
template<typename Array> void fmin(Array &arr){
	typename remove_all_extents<Array>::type typedef ElementType;
	mem(arr,numeric_limits<ElementType>::min());
}
template<typename Array> void fmin_s(Array &arr){
	typename remove_all_extents<Array>::type typedef ElementType;
	mem(arr,numeric_limits<ElementType>::min()/2);
}
mt19937_64 _Random(system_clock::now().time_since_epoch().count());
template<typename _Type> _Type _Rand(_Type l,_Type r){
	return uniform_int_distribution<_Type>(l,r)(_Random);
}
template<typename _Type> void srand(_Type _Seed){
	_Random.seed(_Seed);
}
int rand(){
	return _Rand(0,RAND_MAX);
}
#ifdef _INT_TO_LL
#define int long long
#define INT_MAX LLONG_MAX
#define INT_MIN LLONG_MIN
#endif
template<typename _Type,typename _Compare> using _CPQ=std::priority_queue<_Type,vector<_Type>,_Compare>;
template<typename _Type> using _GPQ=_CPQ<_Type,greater<>>;
template<typename _Type> using _PQ=std::priority_queue<_Type>;
template<typename _Key,typename _Type> using _MM=multimap<_Key,_Type>;
template<typename _Type> using _MS=multiset<_Type>;
template<typename _Type> using _P=pair<_Type,_Type>;
template<typename _Key,typename _Type> using _UM=unordered_map<_Key,_Type>;
template<typename _Type> using _US=unordered_set<_Type>;
template<typename _Key,typename _Type> using _UMM=unordered_multimap<_Key,_Type>;
template<typename _Type> using _UMS=unordered_multiset<_Type>;
template<typename _Type> using _V=vector<_Type>;
constexpr ui64 HashP=1313131313131313131ull,HashP1=1111111111111111171ull,HashP2=37093201209218101ull,HashP3=3113333333333333333ull,HashP4=4444444444444444409ull,HashP5=370903201209218177ull;
constexpr int mod3=998244353,mod7=1000000007,mod9=1000000009,d4[4][2]={{0,1},{1,0},{0,-1},{-1,0}},d8[8][2]={{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1}};
using _Pi=_P<int>;
using _Vi=_V<int>;
using _Vpi=_V<_Pi>;
istream& operator>>(istream& in,i128& a){
	a=0;
	char ch;
	bool fl;
	while(isspace((in.get(ch),ch)));
	fl=(ch==45?ch=in.get(),1:0);
	while(isdigit(ch)){
		(a*=10)+=ch^48;
		in.get(ch);
	}
	if(fl){
		a=-a;
	}
	return in;
}
istream& operator>>(istream& in,ui128& a){
	a=0;
	char ch;
	while(isspace((in.get(ch),ch)));
	while(isdigit(ch)){
		(a*=10)+=ch^48;
		in.get(ch);
	}
	return in;
}
ostream& operator<<(ostream& out,const i128& a){
	if(a<0){
		out<<'-';
		out<<-a;
		return out;
	}
	if(a<10){
		out<<char(a^48);
		return out;
	}
	out<<a/10;
	return out<<a%10;
}
ostream& operator<<(ostream& out,const ui128& a){
	if(a<10){
		out<<char(a^48);
		return out;
	}
	out<<a/10;
	return out<<a%10;
}
istream& read(istream& in){
	return in;
}
template<typename _Type,typename... _Args>istream& read(istream& in,_Type a,_Args ...args){
	in>>a;
	return read(in,args...);
}
ostream& write(ostream& out){
	return out;
}
template<typename _Type,typename... _Args>ostream& write(ostream& out,_Type a,_Args ...args){
	out<<a;
	return write(out,args...);
}
#define y0 __Y0_By_MySelf__
#define y1 __Y1_By_MySelf__
#define yn __Yn_By_MySelf__
#define j0 __J0_By_MySelf__
#define j1 __J1_By_MySelf__
#define jn __Jn_By_MySelf__
#define _FF(_Name,_Begin,_End) for(auto _Name=(_Begin);_Name<(_End);_Name++)
#define _RF(_Name,_Begin,_End) for(auto _Name=(_Begin);_Name>(_End);_Name--)
#define _FE(_Container,...) for(auto __VA_ARGS__:_Container)
#define _SP(_Digit) fixed<<setprecision(_Digit)
#define _Max(...) max({__VA_ARGS__})
#define _Min(...) min({__VA_ARGS__})
#define tostr(_Name) std::to_string(_Name)
#ifndef ONLINE_JUDGE
void pt(){
	cerr<<endl;
}
template<typename _Slipt,typename _End,typename _Type> void pt(_Slipt,_End end,_Type a){
	cerr<<a<<end;
}
template<typename _Slipt,typename _End,typename _Type,typename... _Args> void pt(_Slipt slipt,_End end,_Type a,_Args ...args){
	cerr<<a<<slipt;
	pt(slipt,end,args...);
}
template<typename... _Args> void psp(_Args ...args){
	pt(' ',' ',args...);
}
template<typename... _Args> void pln(_Args ...args){
	pt(' ','\n',args...);
}
template<typename _Type> void __psth(_Type line){
	static int cnt;
	pt("","","\n-------------------------No.",cnt," Line:",line,"-------------------------\n");
	cnt++;
}
#define psth() __psth(__LINE__)
#else
#define pt(...)
#define psp(...)
#define pln(...)
#define psth(...)
#define __psth(...)
#endif
#endif
int t,m,n,c,sum,p[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597,1601,1607,1609,1613,1619,1621,1627,1637,1657,1663,1667,1669,1693,1697,1699,1709,1721,1723,1733,1741,1747,1753,1759,1777,1783,1787,1789,1801,1811,1823,1831,1847,1861,1867,1871,1873,1877,1879,1889,1901,1907,1913,1931,1933,1949,1951,1973,1979,1987,1993,1997,1999,2003,2011,2017,2027,2029,2039,2053,2063,2069,2081,2083,2087,2089,2099,2111,2113,2129,2131,2137,2141,2143,2153,2161,2179,2203,2207,2213,2221,2237,2239,2243,2251,2267,2269,2273,2281,2287,2293,2297,2309,2311,2333,2339,2341,2347,2351,2357,2371,2377,2381,2383,2389,2393,2399,2411,2417,2423,2437,2441,2447,2459,2467,2473,2477,2503,2521,2531,2539,2543,2549,2551,2557,2579,2591,2593,2609,2617,2621,2633,2647,2657,2659,2663,2671,2677,2683,2687,2689,2693,2699,2707,2711,2713,2719,2729,2731,2741,2749,2753,2767,2777,2789,2791,2797,2801,2803,2819,2833,2837,2843,2851,2857,2861,2879,2887,2897,2903,2909,2917,2927,2939,2953,2957,2963,2969,2971,2999,3001,3011,3019,3023,3037,3041,3049,3061,3067,3079,3083,3089,3109,3119,3121,3137,3163,3167,3169,3181,3187,3191,3203,3209,3217,3221,3229,3251,3253,3257,3259,3271,3299,3301,3307,3313,3319,3323,3329,3331,3343,3347,3359,3361,3371,3373,3389,3391,3407,3413,3433,3449,3457,3461,3463,3467,3469,3491,3499,3511,3517,3527,3529,3533,3539,3541,3547,3557,3559,3571,3581,3583,3593,3607,3613,3617,3623,3631,3637,3643,3659,3671,3673,3677,3691,3697,3701,3709,3719,3727,3733,3739,3761,3767,3769,3779,3793,3797,3803,3821,3823,3833,3847,3851,3853,3863,3877,3881,3889,3907,3911,3917,3919,3923,3929,3931,3943,3947,3967,3989,4001,4003,4007,4013,4019,4021,4027,4049,4051,4057,4073,4079,4091,4093,4099,4111,4127,4129,4133,4139,4153,4157,4159,4177,4201,4211,4217,4219,4229,4231,4241,4243,4253,4259,4261,4271,4273,4283,4289,4297,4327,4337,4339,4349,4357,4363,4373,4391,4397,4409,4421,4423,4441,4447,4451,4457,4463,4481,4483,4493,4507,4513,4517,4519,4523,4547,4549,4561,4567,4583,4591,4597,4603,4621,4637,4639,4643,4649,4651,4657,4663,4673,4679,4691,4703,4721,4723,4729,4733,4751,4759,4783,4787,4789,4793,4799,4801,4813,4817,4831,4861,4871,4877,4889,4903,4909,4919,4931,4933,4937,4943,4951,4957,4967,4969,4973,4987,4993,4999};
int poww(int a,int b){
	int ans=1;
	while(b){
		if(b&1){
			(ans*=a)%=m;
		}
		(a*=a)%=m;
		b>>=1;
	}
	return ans;
}
struct stu{
	int cnt[(sizeof p>>3)+5]={};
	stu(int n=1){
		_FF(i,0,sizeof p>>3){
			while(!(n%p[i])){
				n/=p[i];
				cnt[i]++;
			}
		}
	}
	stu operator*(stu b){
		stu ans;
		_FF(i,0,sizeof p>>3){
			ans.cnt[i]=cnt[i]+b.cnt[i];
		}
		return ans;
	}
	stu& operator*=(stu b){
		return *this=*this*b;
	}
	stu operator/(stu b){
		stu ans;
		_FF(i,0,sizeof p>>3){
			ans.cnt[i]=cnt[i]-b.cnt[i];
		}
		return ans;
	}
	stu& operator/=(stu b){
		return *this=*this/b;
	}
}fac[5005],ans;
ostream& operator<<(ostream& out,const stu& a){
	int ans=1;
	_FF(i,0,sizeof p>>3){
		(ans*=poww(p[i],a.cnt[i]))%=m;
	}
	return out<<ans;
}
signed main(){
#ifdef _CLOSE_SYNC
	cin.tie(0)->sync_with_stdio(0);
#endif
#ifdef _USE_FREOPEN
	ifstream fin(".in");
	ofstream fout(".out");
	cin.rdbuf(fin.rdbuf());
	cout.rdbuf(fout.rdbuf());
#endif
	cin>>t>>m;
	fac[0]=1;
	_FF(i,1,5005){
		fac[i]=fac[i-1]*i;
	}
	while(t--){
		ans=1;
		sum=0;
		cin>>n;
		while(n--){
			cin>>c;
			sum+=c;
			ans/=fac[c];
		}
		ans*=fac[sum];
		cout<<ans<<'\n';
	}
	return 0;
}

提出情報

提出日時
問題 E - Count Sequences 2
ユーザ Alex866
言語 C++ 20 (gcc 12.2)
得点 450
コード長 10265 Byte
結果 AC
実行時間 1543 ms
メモリ 30044 KiB

コンパイルエラー

Main.cpp:64: warning: "INT_MAX" redefined
   64 | #define INT_MAX LLONG_MAX
      | 
In file included from /usr/include/c++/12/climits:42,
                 from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/12/bits/extc++.h:32,
                 from Main.cpp:1:
/usr/lib/gcc/x86_64-linux-gnu/12/include/limits.h:120: note: this is the location of the previous definition
  120 | #define INT_MAX __INT_MAX__
      | 
Main.cpp:65: warning: "INT_MIN" redefined
   65 | #define INT_MIN LLONG_MIN
      | 
/usr/lib/gcc/x86_64-linux-gnu/12/include/limits.h:118: note: this is the location of the previous definition
  118 | #define INT_MIN (-INT_MAX - 1)
      | 
Main.cpp: In constructor ‘stu::stu(long long int)’:
Main.cpp:149:61: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
  149 | #define _FF(_Name,_Begin,_End) for(auto _Name=(_Begin);_Name<(_End);_Name++)
      |                                                             ^
Main.cpp:202:17: note: in expansion of macro ‘_FF’
  202 |                 _FF(i,0,sizeof p>>3){
      |                 ^~~
Main.cpp: In member function ‘stu stu::operator*(stu)’:
Main.cpp:149:61: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
  149 | #define _FF(_Name,_Begin,_End) for(auto _Name=(_Begin);_Name<(_End);_Name++)
      |                                                             ^
Main.cpp:211:17: note: in expansion of macro ‘_FF’
  211 |                 _FF(i,0,sizeof p>>3){
      |                 ^~~
Main.cpp: In member function ‘stu stu::operator/(stu)’:
Main.cpp:149:61: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
  149 | #define _FF(_Name,_Begin,_End) for(auto _Name=(_Begin);_Name<(_End);_Name++)
      |                                                             ^
Main.cpp:221:17: note: in expansion of macro ‘_FF’
  221 |                 _FF(i,0,sizeof p>>3){
      |                 ^~~
Main.cpp: In function ‘std::ostream& operator<<(std::ostream&, const stu&)’:
Main.cpp:149:61: warning: comparison of integer expressions of different signedness: ‘int’ and ‘long unsigned int’ [-Wsign-compare]
  149 | #define _FF(_Name,_Begin,_End) for(auto _Name=(_Begin);_Name<(_End);_Name++)
      |                                                             ^
Main.cpp:232:9: note: in expansion of macro ‘_FF’
  232 |         _FF(i,0,sizeof p>>3){
      |         ^~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 2
AC × 51
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt, 01_test_37.txt, 01_test_38.txt, 01_test_39.txt, 01_test_40.txt, 01_test_41.txt, 01_test_42.txt, 01_test_43.txt, 01_test_44.txt, 01_test_45.txt, 01_test_46.txt, 01_test_47.txt, 01_test_48.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 43 ms 30032 KiB
00_sample_01.txt AC 43 ms 29904 KiB
01_test_00.txt AC 771 ms 29912 KiB
01_test_01.txt AC 993 ms 29796 KiB
01_test_02.txt AC 1499 ms 29924 KiB
01_test_03.txt AC 772 ms 29920 KiB
01_test_04.txt AC 995 ms 29884 KiB
01_test_05.txt AC 1509 ms 29920 KiB
01_test_06.txt AC 771 ms 29916 KiB
01_test_07.txt AC 997 ms 30044 KiB
01_test_08.txt AC 1500 ms 29792 KiB
01_test_09.txt AC 772 ms 29920 KiB
01_test_10.txt AC 994 ms 29920 KiB
01_test_11.txt AC 1519 ms 29792 KiB
01_test_12.txt AC 766 ms 29792 KiB
01_test_13.txt AC 997 ms 30044 KiB
01_test_14.txt AC 1527 ms 29924 KiB
01_test_15.txt AC 767 ms 29920 KiB
01_test_16.txt AC 998 ms 29920 KiB
01_test_17.txt AC 1498 ms 29924 KiB
01_test_18.txt AC 768 ms 29912 KiB
01_test_19.txt AC 1002 ms 29984 KiB
01_test_20.txt AC 1504 ms 29920 KiB
01_test_21.txt AC 765 ms 29908 KiB
01_test_22.txt AC 997 ms 29920 KiB
01_test_23.txt AC 1509 ms 29884 KiB
01_test_24.txt AC 788 ms 29900 KiB
01_test_25.txt AC 994 ms 30044 KiB
01_test_26.txt AC 1523 ms 29920 KiB
01_test_27.txt AC 766 ms 29908 KiB
01_test_28.txt AC 995 ms 29900 KiB
01_test_29.txt AC 1504 ms 29904 KiB
01_test_30.txt AC 764 ms 29880 KiB
01_test_31.txt AC 1002 ms 29920 KiB
01_test_32.txt AC 1504 ms 29856 KiB
01_test_33.txt AC 767 ms 30004 KiB
01_test_34.txt AC 999 ms 29896 KiB
01_test_35.txt AC 1501 ms 29944 KiB
01_test_36.txt AC 766 ms 29852 KiB
01_test_37.txt AC 1003 ms 29860 KiB
01_test_38.txt AC 1511 ms 30004 KiB
01_test_39.txt AC 766 ms 29900 KiB
01_test_40.txt AC 993 ms 29924 KiB
01_test_41.txt AC 1510 ms 29920 KiB
01_test_42.txt AC 765 ms 29896 KiB
01_test_43.txt AC 1003 ms 29988 KiB
01_test_44.txt AC 1503 ms 29860 KiB
01_test_45.txt AC 767 ms 29988 KiB
01_test_46.txt AC 1000 ms 29876 KiB
01_test_47.txt AC 1501 ms 29796 KiB
01_test_48.txt AC 1543 ms 29944 KiB