提出 #54576656
ソースコード 拡げる
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define REP_(I,N) for (int I=0,END=(N);I<END;I++)
#define rREP_(I,N) for (int I=(N)-1;I>=0;I--)
#define rep_(I,S,N) for (int I=(S),END=(N);I<END;I++)
#define rrep_(I,S,N) for (int I=(N)-1,START=(S);I>=START;I--)
#define FOR_(I,S,N) for (int I=(S),END=(N);I<=END;I++)
#define rFOR_(I,S,N) for (int I=(N),START=(S);I>=START;I--)
#define DEBUG
#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define deputs(str) fprintf(stderr, "%s\n",str)
#else
#define debug(...)
#define deputs(str)
#endif // DEBUG
typedef unsigned long long ULL;
typedef unsigned long long ull;
typedef long long LL;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF=0x3f3f3f3f;
const LL INFF=0x3f3f3f3f3f3f3f3fll;
const LL maxn=2e5+7;
const double pi=acos(-1.0);
const double eps=1e-10;
template<typename T>inline void pr2(T x,int k=64) {REP_(i,k) printf("%d",(x>>i)&1); putchar(' ');}
template<typename T>inline void max_(T &A,T B) {(A<B) &&(A=B);}
template<typename T>inline void min_(T &A,T B) {(A>B) &&(A=B);}
inline ll fastgcd(ll a, ll b) { // __gcd()
if (!b) return a;
ll az=__builtin_ctzll(a),bz=__builtin_ctzll(b),z=min(az,bz),diff; b>>=bz;
while (a) {
a>>=az, diff=b-a, az=__builtin_ctzll(diff);
(b>a)&&(b=a), a=abs(diff);
}
return b<<z;
}
int startTime;
void startTimer() {startTime=clock();}
void printTimer() {debug("/--- Time: %ld milliseconds ---/\n",clock()-startTime);}
typedef array<int,5> ar5;
typedef array<int,4> ar4;
typedef array<int,3> ar3;
std::mt19937 rng(time(0));
std::mt19937_64 rng64(time(0));
vector<pii> direction4 = {{-1,0},{0,-1},{0,1},{1,0}};
vector<pii> direction8 = {{-1,-1},{-1,0},{1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
// const int mod = 1e9+7;
const int mod=998244353;
struct mint {
long long x;
mint():x(0) {}
mint(long long x):x((x%mod+mod)%mod) {}
// mint(long long x):x(x){}
mint &fix() { x = (x%mod+mod)%mod; return *this; }
mint operator-() const { return mint(0) - *this; }
mint operator~() const { return mint(1) / *this; }
mint &operator+=(const mint &a) { if ((x+=a.x)>=mod) x-=mod; return *this; }
mint &operator-=(const mint &a) { if ((x+=mod-a.x)>=mod) x-=mod; return *this; }
mint &operator*=(const mint &a) { (x*=a.x)%=mod; return *this; }
mint &operator/=(const mint &a) { (x*=a.pow(mod-2).x)%=mod; return *this; }
mint operator+(const mint &a)const { return mint(*this) += a; }
mint operator-(const mint &a)const { return mint(*this) -= a; }
mint operator*(const mint &a)const { return mint(*this) *= a; }
mint operator/(const mint &a)const { return mint(*this) /= a; }
mint pow(long long t) const {
mint ret=1,cur=x;
for (; t; t>>=1ll,cur=cur*cur)
if (t&1) ret=ret*cur;
return ret;
}
bool operator<(const mint &a)const { return x < a.x; }
bool operator==(const mint &a)const { return x == a.x; }
};
istream & operator>>(istream &o,mint &a) { o>>a.x; a=a.fix(); return o; }
ostream & operator<<(ostream &o,const mint &a) { o<<a.x; return o; }
struct comb {
vector<mint> f, g; // f:fac; g:inv
comb() {}
comb(int mx) : f(mx + 1), g(mx + 1) {
f[0] = 1;
FOR_(i, 1, mx) f[i] = f[i - 1] * i;
g[mx] = f[mx].pow(mod - 2);
rFOR_(i, 1, mx) g[i - 1] = g[i] * i;
}
mint operator()(int a, int b) {
if (b < 0 || a < b)
return 0;
return f[a] * g[b] * g[a - b];
}
} Comb(maxn); // Combination(x,y)
int solve() {
int n,k;
scanf("%d",&k);
vector<mint> way(k+1);
way[0]=1;
REP_(_,26) {
int x;
scanf("%d",&x);
rFOR_(i,0,k) FOR_(d,1,min(k-i,x)) way[i+d]+=way[i]*Comb.g[d];
// FOR_(i,0,k) printf("%lld ",way[i].x); puts("<- way");
}
mint res=0;
FOR_(i,1,k) res+=way[i]*Comb.f[i];
printf("%lld\n",res.x);
return 0;
}
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(0), cout.tie(0);
int T = 1;
// cin>>T;
// scanf("%d",&T);
startTimer();
FOR_(_, 1, T) { solve(); }
// printTimer();
}
/*
*/
提出情報
| 提出日時 |
|
| 問題 |
E - Alphabet Tiles |
| ユーザ |
zlc1114 |
| 言語 |
C++ 20 (gcc 12.2) |
| 得点 |
475 |
| コード長 |
4427 Byte |
| 結果 |
AC |
| 実行時間 |
23 ms |
| メモリ |
6264 KiB |
コンパイルエラー
Main.cpp: In function ‘int solve()’:
Main.cpp:100:9: warning: unused variable ‘n’ [-Wunused-variable]
100 | int n,k;
| ^
Main.cpp:101:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
101 | scanf("%d",&k);
| ~~~~~^~~~~~~~~
Main.cpp:106:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
106 | scanf("%d",&x);
| ~~~~~^~~~~~~~~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
475 / 475 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
sample00.txt, sample01.txt, sample02.txt |
| All |
sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| sample00.txt |
AC |
4 ms |
6160 KiB |
| sample01.txt |
AC |
4 ms |
6152 KiB |
| sample02.txt |
AC |
23 ms |
6164 KiB |
| testcase00.txt |
AC |
4 ms |
6152 KiB |
| testcase01.txt |
AC |
4 ms |
6152 KiB |
| testcase02.txt |
AC |
4 ms |
6216 KiB |
| testcase03.txt |
AC |
5 ms |
6152 KiB |
| testcase04.txt |
AC |
6 ms |
6152 KiB |
| testcase05.txt |
AC |
4 ms |
6244 KiB |
| testcase06.txt |
AC |
16 ms |
6168 KiB |
| testcase07.txt |
AC |
9 ms |
6156 KiB |
| testcase08.txt |
AC |
8 ms |
6116 KiB |
| testcase09.txt |
AC |
4 ms |
6160 KiB |
| testcase10.txt |
AC |
15 ms |
6244 KiB |
| testcase11.txt |
AC |
12 ms |
6264 KiB |
| testcase12.txt |
AC |
5 ms |
6164 KiB |
| testcase13.txt |
AC |
4 ms |
6136 KiB |
| testcase14.txt |
AC |
11 ms |
6216 KiB |
| testcase15.txt |
AC |
5 ms |
6184 KiB |
| testcase16.txt |
AC |
13 ms |
6220 KiB |
| testcase17.txt |
AC |
4 ms |
6244 KiB |
| testcase18.txt |
AC |
4 ms |
6144 KiB |