結果
問題 | No.1631 Sorting Integers (Multiple of K) Easy |
ユーザー |
![]() |
提出日時 | 2021-07-30 22:09:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,703 bytes |
コンパイル時間 | 1,690 ms |
コンパイル使用メモリ | 126,308 KB |
最終ジャッジ日時 | 2025-01-23 11:50:36 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 WA * 11 TLE * 5 |
ソースコード
#include <iostream>#include <algorithm>#include <iomanip>#include <vector>#include <queue>#include <set>#include <map>#include <tuple>#include <cmath>#include <numeric>#include <functional>#include <cassert>#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }using namespace std;template<typename T>vector<vector<T>> vec2d(int n, int m, T v){return vector<vector<T>>(n, vector<T>(m, v));}template<typename T>vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));}typedef long long ll;int main(){ios::sync_with_stdio(false);cin.tie(0);cout << setprecision(10) << fixed;int n, k; cin >> n >> k;vector<int> c(10);for(int i = 1; i <= 9; i++) cin >> c[i];vector<int> v;for(int i = 1; i <= 9; i++){for(int j = 0; j < c[i]; j++) v.push_back(i);}auto dp = vec3d<ll>(2, 1<<n, k, 0);dp[0][0][0] = 1;vector<int> pow10(n);pow10[0] = 1%k;for(int i = 1; i < n; i++){pow10[i] = (pow10[i-1]*10)%k;}vector<bool> ok(1<<n);auto judge = [&](int s)->bool{int sum = 0;for(int i = 1; i <= 9; i++){for(int j = sum; j < sum+c[i]; j++){for(int k = j+1; k < sum+c[i]; k++){if(s&(1<<j)){if(!(s&(1<<k))) return false;}}}sum += c[i];}return true;};for(int i = 0; i < 1<<n; i++) ok[i] = judge(i);for(int i = 0; i < n; i++){int cur = (i+1)%2;int pre = cur^1;// cout << cur << ' ' << pre << endl;for(int j = 0; j < 1<<n; j++){for(int l = 0; l < k; l++){dp[cur][j][l] = 0;}}for(int j = 0; j < 1<<n; j++){if(!ok[j]) continue;vector<int> u;for(int l = 0; l < n; l++){if(j&(1<<l)) continue;u.push_back(l);}for(int l = 0; l < k; l++){for(int s: u){int nx = (l+pow10[s]*v[i])%k;int nxs = j+(1<<s);if(ok[nxs]) dp[cur][nxs][nx] += dp[pre][j][l];}}}}cout << dp[n%2][(1<<n)-1][0] << endl;}