結果
| 問題 | No.1634 Sorting Integers (Multiple of K) Hard |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-30 22:22:45 |
| 言語 | C++14 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
TLE
不安定
|
| 実行時間 | - |
| コード長 | 765 bytes |
| 記録 | |
| コンパイル時間 | 445 ms |
| コンパイル使用メモリ | 89,216 KB |
| 実行使用メモリ | 432,512 KB |
| 最終ジャッジ日時 | 2026-08-28 09:05:50 |
| 合計ジャッジ時間 | 15,206 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 4 TLE * 1 -- * 23 |
コンパイルメッセージ
main.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
38 | main()
| ^~~~
ソースコード
#include<iostream>
#include<map>
using namespace std;
int N,K,c[14];
long V=1;
map<pair<int,int>,long>mp;
void dfs1(int k,int now,int rest)
{
if(rest==0)
{
mp[make_pair(k,now)]++;
}
else
{
for(int i=0;i<N;i++)if(!(k>>i&1))
{
dfs1(k|1<<i,(now*10L+c[i])%K,rest-1);
}
}
}
long ans=0;
long P10;
void dfs2(int k,int now,int rest)
{
if(rest==0)
{
pair<int,int>p=make_pair((1<<N)-1-k,(K-now*P10%K)%K);
if(mp.find(p)!=mp.end())ans+=mp[p];
}
else
{
for(int i=0;i<N;i++)if(!(k>>i&1))
{
dfs2(k|1<<i,(now*10L+c[i])%K,rest-1);
}
}
}
main()
{
cin>>N>>K;
int sz=0;
for(int i=1;i<=9;i++)
{
int C;cin>>C;
for(;C;V*=C--)c[sz++]=i;
}
dfs1(0,0,N/2);
P10=1;
for(int i=0;i<N/2;i++)P10*=10;
P10%=K;
dfs2(0,0,N-N/2);
cout<<ans/V<<endl;
}