提出 #54594035


ソースコード 拡げる

#include <bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#pragma GCC optimize("O3")
using namespace std;
//using namespace __gnu_pbds;
#define bit(_x) (1 << _x)
#define int long long
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define pyes cout<<"Yes\n"
#define pno cout<<"No\n"
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi vector<int>
#define vvi vector<vector<int>>
typedef long double ld;
const int mod = 998244353;
const int INF = 1e15;
const int N=1e6;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
//cout<<fixed<<setprecision(20)<<mx<<endl;
// vector<int>primes;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     ordered_set;
//cout << fixed << setprecision(7) << ans << '\n';
// (1,0,n-1,l-1,r-1,1);
void deb(){
    cout<<"\n";
}
template <typename T, typename... Types>
void deb(T var1, Types... var2){
    cout<<var1<<" ";
    deb(var2...);
}
template <typename T>
void pv(vector<T>&v){
    for(int i=0;i<v.size();i++){
        cout<<v[i]<<" ";
    }
    cout<<endl;
}

// int check(int mex,vector<int>&a){
//     if(mex==0){
//         return true;
//     }
//     vector<int>cnt(mex,0);
//     for(int x:a){
//         if(x<mex){
//             cnt[x]++;
//         }
//     }
//     sort(all(cnt));
//     if(cnt[0]==0){
//         return false;
//     }
//     if(cnt[0]==1){
//         if(mex>1 and cnt[1]==1){
//             return false;
//         }
//     }
//     return true;
// }
// int bsearch(vector<int>&a){
//     int n=a.size();
//     int l=0,r=n;
// 	while(l<=r){
// 		int mid=(l+r)/2;
// 		if(check(mid,a)){
// 			l=mid+1;
// 		}else{
// 			r=mid-1;
// 		}
// 	}
//     return l-1;
// }
 
 
class presum{
	vector<int>v;
	public:
	presum(vector<int>&a){
		v.resize(a.size());
		int t=0;
		for(int i=0;i<a.size();i++){
			t+=a[i];
			v[i]=t;
		}
	}
	int get(int l,int r){
		if(l==0){
			return v[r];
		}
		return v[r]-v[l-1];
	}
};
int fac[N];
int spf[N];
void sieve(){
    spf[1] = 1;
        for (int i = 2; i < N; i++)
            spf[i] = i;
        for (int i = 4; i < N; i += 2)
            spf[i] = 2;
        for (int i = 3; i * i < N; i++) {
            if (spf[i] == i) {
                for (int j = i * i; j < N; j += i)
                    if (spf[j] == j)
                        spf[j] = i;
            }
        }
}
void calc_fac(){
	fac[0]=1;
	for(int i=1;i<N;i++){
		fac[i]=(fac[i-1]*i)%mod;
	}
}
template <typename T>
void fill(vector<T>&a){
    for(int i=0;i<a.size();i++){
        cin>>a[i];
    }}
int modpower(int x, int y){
    if(y==0){
        return 1;
    }
    int res = 1;
    x = x % mod;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}
int modInverse(int n){return modpower(n, mod - 2);}
int nCrModPFermat(int n,int r)
{   
    //deb("fn",n,r);
    if (n < r)
        return 0;
    if (r == 0)
        return 1;
    return (fac[n] * modInverse(fac[r]) % mod
            * modInverse(fac[n - r]) % mod)
           % mod;
}
bool is_bound(pii p,int n,int m){
    if(p.first < 0 || p.first>=n || p.second<0 || p.second >=m){
        //deb(p.F,p.S);
        return false;
    }
    
    return true;
}
 

 
vector<pii>dirs={{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
vector<pii>dirs2={{-1,0},{0,1},{1,0},{0,-1}};
vector<pii>dirs3={{0,0},{1,0},{0,1},{1,1}};
void factorize(int tmp,map<int,int>&mp){
    mp.clear();
    while(tmp>1){
        mp[spf[tmp]]++;
        tmp/=spf[tmp];
    }
    return;
}
map<char,int>mpd={{'U',0},{'R',1},{'D',2},{'L',3}};
int nc2(int n){
    return (n*(n-1))/2;
}
 
// bool dfs(int node,vector<vector<int>>&adj,vector<int>&vis,vector<int>&par){

// }
 

void primeFactors(int n,map<int,int>&mp) 
{ 
    while (n % 2 == 0) 
    { 
        mp[2]++;
        n = n/2; 
    } 
 
    // n must be odd at this point. So we can skip 
    // one element (Note i = i +2) 
    for (int i = 3; i <= sqrt(n); i = i + 2) 
    { 
        // While i divides n, print i and divide n 
        while (n % i == 0) 
        { 
            mp[i]++;
            n = n/i; 
        } 
    } 
 
    // This condition is to handle the case when n 
    // is a prime number greater than 2 
    if (n > 2) 
        mp[n]++;
} 

vector<int>par(2e5+10),opp(2e5,-1);
int find_par(int v){
    if(v==par[v]){
        return v;
    }
    return par[v]=find_par(par[v]);
}
void merge(int u,int v){
    int pu=find_par(u);
    int pv=find_par(v);
    par[pv]=pu;
}


// vector<pii>dirs2={{-1,0},{0,1},{1,0},{0,-1}};
int smallestDivisor(int n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;
 
    // iterate from 3 to sqrt(n)
    for (int i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }
 
    return n;
}
void solve(int ttc){
    int k;
    cin>>k;
    vi c(26);
    fill(c);
    vvi dp(k+1,vi(26,0));
    for(int i=1;i<=k;i++){
        for(int j=0;j<26;j++){
            if(j==0){
                if(i<=c[0]){
                    dp[i][j]=1;
                }
               // deb(i,j,dp[i][j]);
                continue;
            }
            dp[i][j]=dp[i][j-1];
            if(i<=c[j]){
                dp[i][j]++;
            }
            for(int cnt=1;cnt<=min(c[j],i);cnt++){
                dp[i][j]+=dp[i-cnt][j-1]*nCrModPFermat(i,cnt);
                dp[i][j]%=mod;
            }
            //deb(i,j,dp[i][j]);
        }
    }
    int ans=0;
    for(int i=1;i<=k;i++){
        ans+=dp[i][25];
        ans%=mod;
    }
    cout<<ans<<endl;
} 

signed main(){
    //ISSUE ONLY IF N<K ?
    //K<SQRTN K>SQRTN ?
    ios::sync_with_stdio(false);
    cin.tie(NULL);
	int t=1;
	//cin>>t;
    calc_fac();
    //sieve();
	for(int i=1;i<=t;i++){
        //int n,k;
        //cin>>n>>k;
		solve(i);
	}
	
}

提出情報

提出日時
問題 E - Alphabet Tiles
ユーザ S__32
言語 C++ 20 (gcc 12.2)
得点 0
コード長 6251 Byte
結果 TLE
実行時間 2208 ms
メモリ 14500 KiB

コンパイルエラー

Main.cpp: In constructor ‘presum::presum(std::vector<long long int>&)’:
Main.cpp:89:30: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   89 |                 for(int i=0;i<a.size();i++){
      |                             ~^~~~~~~~~
Main.cpp: In function ‘void solve(long long int)’:
Main.cpp:243:16: warning: unused parameter ‘ttc’ [-Wunused-parameter]
  243 | void solve(int ttc){
      |                ^
Main.cpp: In instantiation of ‘void fill(std::vector<_Tp>&) [with T = long long int]’:
Main.cpp:247:9:   required from here
Main.cpp:125:18: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  125 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 475
結果
AC × 2
TLE × 1
AC × 20
TLE × 2
セット名 テストケース
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 8 ms 14196 KiB
sample01.txt AC 9 ms 14188 KiB
sample02.txt TLE 2208 ms 14496 KiB
testcase00.txt AC 42 ms 14332 KiB
testcase01.txt AC 33 ms 14376 KiB
testcase02.txt AC 33 ms 14480 KiB
testcase03.txt AC 129 ms 14148 KiB
testcase04.txt AC 355 ms 14236 KiB
testcase05.txt AC 75 ms 14256 KiB
testcase06.txt TLE 2037 ms 14424 KiB
testcase07.txt AC 882 ms 14380 KiB
testcase08.txt AC 712 ms 14468 KiB
testcase09.txt AC 17 ms 14172 KiB
testcase10.txt AC 1761 ms 14472 KiB
testcase11.txt AC 1278 ms 14388 KiB
testcase12.txt AC 241 ms 14232 KiB
testcase13.txt AC 9 ms 14188 KiB
testcase14.txt AC 1115 ms 14412 KiB
testcase15.txt AC 172 ms 14064 KiB
testcase16.txt AC 1484 ms 14500 KiB
testcase17.txt AC 47 ms 14144 KiB
testcase18.txt AC 9 ms 14448 KiB