結果
| 問題 |
No.1631 Sorting Integers (Multiple of K) Easy
|
| コンテスト | |
| ユーザー |
inksamurai
|
| 提出日時 | 2021-07-30 21:25:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,437 bytes |
| コンパイル時間 | 1,523 ms |
| コンパイル使用メモリ | 124,948 KB |
| 実行使用メモリ | 14,016 KB |
| 最終ジャッジ日時 | 2024-09-15 22:53:52 |
| 合計ジャッジ時間 | 6,594 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 11 TLE * 1 -- * 16 |
ソースコード
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <assert.h>
#include <cstring>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define vi vector <int>
#define vec(...) vector<__VA_ARGS__>
#define _3laEQ3x ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//eodefine
using namespace std;
const int mxn=400000;
using wtfpii = tuple<int,vi,int>;
int mod;
struct modularint{
ll x;
modularint(ll x=0):x(x%mod){}
modularint& operator+=(const modularint a){
if ((x += a.x) >= mod) x -= mod;
return *this;
}
modularint& operator-=(const modularint a){
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
modularint& operator*=(const modularint a){
(x *= a.x) %= mod;
return *this;
}
modularint operator+(const modularint a)const{
modularint res(*this);
return res+=a;
}
modularint operator-(const modularint a)const{
modularint res(*this);
return res-=a;
}
modularint operator*(const modularint a)const{
modularint res(*this);
return res*=a;
}
modularint pow(int n)const{
modularint res=1,x(*this);
while(n){
if(n&1)res*=x;
x*=x;
n>>=1;
}
return res;
}
modularint inv()const{
return pow(mod-2);
}
};
using mint=modularint;
int n;
vec(mint) pot;
map<wtfpii,int> mp;
vi a;
int f(int i,mint s){
if(mp.find({i,a,s.x})!=mp.end()) return mp[{i,a,s.x}];
if(i==n and s.x==0) return 1;
int now=0;
rep(j,9){
if(a[j]>0){
a[j]--;
mint e=(j+1);
now += f(i+1,s+e*pot[i]);
a[j]++;
}
}
return mp[{i,a,s.x}]=now;
}
int main(){
_3laEQ3x;
cin>>n>>mod;
rep(i,9) { int x; cin>>x; a.pb(x); }
pot.pb(1);
drep(i,n-1){
pot.pb(pot.back()*10);
}
reverse(all(pot));
cout<<f(0,0)<<"\n";
//
return 0;
}
inksamurai