ログインしてください。
提出 #48248921
ソースコード 拡げる
// LUOGU_RID: 138549584
#include<bits/stdc++.h>
#include<atcoder/modint>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef atcoder::modint998244353 mint;
#define rep(i,l,r) for(int i(l);i<=(r);++i)
#define per(i,r,l) for(int i(r);i>=(l);--i)
#define eb emplace_back
#define File(filename) freopen(filename ".in","r",stdin),freopen(filename ".out","w",stdout)
#ifdef EXODUS
#define Debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define Debug(...) 0
#endif
//=========================================================================================================
// Something about IO
template<typename T>
void read(T &x){
x=0;T flg=1;
char ch=getchar();
while(!isdigit(ch)){if(ch=='-')flg=-1;ch=getchar();}
while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
x*=flg;
}
template<typename T,typename... Args>
void read(T &x,Args &...args){read(x),read(args...);}
//=========================================================================================================
// Define the global variables here.
bool membg=0;
constexpr int N=1e6+7,S=(1<<19)+7;
int n,m,K,pos[N],lim[S];
bool invaild[S];
ll a[N],b[N];
mint inv[N],f[S],C[20][20],val[20],ans;
bool memed=0;
//=========================================================================================================
// Code here.
mint calc(int x,int y){
if(x<y)return (mint)0;
mint res=0;
for(int i=0;i<=y;i++)res+=C[y][i]*(((y-i)&1)?-1:1)*mint(i).pow(x);
for(int i=1;i<=y;i++)res=res*inv[i];
return res;
}
void solve(){
read(n,m,K);
inv[0]=1;for(int i=1;i<=K;i++)inv[i]=(mint)1/i;
for(int i=(C[0][0]=1).val();i<=K;i++)
for(int j=(C[i][0]=1).val();j<=i;j++)
C[i][j]=C[i-1][j]+C[i-1][j-1];
for(int i=1;i<=n;i++)read(a[i]);
for(int i=1;i<=n;i++)read(b[i]);
set<pair<ll,int>>st;
for(int i=1;i<=n;i++)st.emplace(a[i],i);
for(int i=1;i<=n;i++){
auto it=st.lower_bound({b[i],0});
pos[i]=it->second;st.erase(it);
}
for(int i=1,s=0,t=0;i<n;i++,s=0,t=0){
ll now=b[i],nxt=b[i+1];
for(int k=0;k<K;k++){
if(now%10<nxt%10)s|=(1<<k);
if(now%10>nxt%10)t|=(1<<k);
now/=10,nxt/=10;
}
lim[s]|=t;
if(pos[i]>pos[i+1])
invaild[s]=true;
}
// for(int s=0;s<(1<<K);s++)printf("%d\n",lim[s]);
// for(int s=0;s<(1<<K);s++)printf("%d\n",invaild[s]);
for(int s=0;s<(1<<K);s++)
for(int k=0;k<K;k++)
if((s>>k)&1)
lim[s]|=lim[s^(1<<k)],invaild[s]|=invaild[s^(1<<k)];
f[0]=1;
for(int s=0;s<(1<<K);s++)
for(int k=0;k<K;k++)
if((!(s&(1<<k)))&&(!((lim[((1<<K)-1)^s]>>k)&1)))
f[s|(1<<k)]+=f[s];
// for(int s=0;s<(1<<K);s++)printf("%d\n",f[s].val());
for(int i=0;i<=K;i++)val[i]=calc(m,i);
// for(int i=0;i<=K;i++)printf("%d\n",val[i]);
for(int s=0;s<(1<<K);s++)
if(!invaild[((1<<K)-1)^s])
ans+=f[s]*val[__builtin_popcount(s)];
printf("%d\n",ans.val());
return;
}
//=========================================================================================================
signed main(){
Debug("%.3lfMB\n",fabs(&memed-&membg)/1024.0/1024.0);
int timbg=clock();
int T=1;
while(T--)solve();
int timed=clock();
Debug("%.3lfs\n",1.0*(timed-timbg)/CLOCKS_PER_SEC);
fflush(stdout);
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | F - Random Radix Sort |
| ユーザ | EXODUS |
| 言語 | C++ 17 (gcc 12.2) |
| 得点 | 900 |
| コード長 | 3315 Byte |
| 結果 | AC |
| 実行時間 | 221 ms |
| メモリ | 27568 KiB |
コンパイルエラー
Main.cpp: In function ‘int main()’:
Main.cpp:20:28: warning: statement has no effect [-Wunused-value]
20 | #define Debug(...) 0
| ^
Main.cpp:111:9: note: in expansion of macro ‘Debug’
111 | Debug("%.3lfMB\n",fabs(&memed-&membg)/1024.0/1024.0);
| ^~~~~
Main.cpp:20:28: warning: statement has no effect [-Wunused-value]
20 | #define Debug(...) 0
| ^
Main.cpp:116:9: note: in expansion of macro ‘Debug’
116 | Debug("%.3lfs\n",1.0*(timed-timbg)/CLOCKS_PER_SEC);
| ^~~~~
Main.cpp:112:13: warning: unused variable ‘timbg’ [-Wunused-variable]
112 | int timbg=clock();
| ^~~~~
Main.cpp:115:13: warning: unused variable ‘timed’ [-Wunused-variable]
115 | int timed=clock();
| ^~~~~
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 900 / 900 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt |
| All | 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 02_small_11.txt, 02_small_12.txt, 02_small_13.txt, 02_small_14.txt, 02_small_15.txt, 02_small_16.txt, 02_small_17.txt, 02_small_18.txt, 02_small_19.txt, 02_small_20.txt, 02_small_21.txt, 02_small_22.txt, 02_small_23.txt, 02_small_24.txt, 02_small_25.txt, 03_rand_1_01.txt, 03_rand_1_02.txt, 03_rand_1_03.txt, 03_rand_1_04.txt, 03_rand_1_05.txt, 04_rand_2_01.txt, 04_rand_2_02.txt, 04_rand_2_03.txt, 04_rand_2_04.txt, 04_rand_2_05.txt, 04_rand_2_06.txt, 04_rand_2_07.txt, 04_rand_2_08.txt, 04_rand_2_09.txt, 04_rand_2_10.txt, 05_rand_3_01.txt, 05_rand_3_02.txt, 05_rand_3_03.txt, 05_rand_3_04.txt, 05_rand_3_05.txt, 05_rand_3_06.txt, 05_rand_3_07.txt, 05_rand_3_08.txt, 05_rand_3_09.txt, 05_rand_3_10.txt, 06_rand_4_01.txt, 06_rand_4_02.txt, 06_rand_4_03.txt, 06_rand_4_04.txt, 06_rand_4_05.txt, 06_rand_4_06.txt, 06_rand_4_07.txt, 06_rand_4_08.txt, 06_rand_4_09.txt, 06_rand_4_10.txt, 07_near_998244353_01.txt, 07_near_998244353_02.txt, 07_near_998244353_03.txt, 07_near_998244353_04.txt, 07_near_998244353_05.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 01_sample_01.txt | AC | 3 ms | 9676 KiB |
| 01_sample_02.txt | AC | 3 ms | 9748 KiB |
| 01_sample_03.txt | AC | 3 ms | 9768 KiB |
| 02_small_01.txt | AC | 3 ms | 9892 KiB |
| 02_small_02.txt | AC | 3 ms | 9820 KiB |
| 02_small_03.txt | AC | 3 ms | 9700 KiB |
| 02_small_04.txt | AC | 3 ms | 9896 KiB |
| 02_small_05.txt | AC | 3 ms | 9824 KiB |
| 02_small_06.txt | AC | 3 ms | 9828 KiB |
| 02_small_07.txt | AC | 3 ms | 9828 KiB |
| 02_small_08.txt | AC | 3 ms | 9896 KiB |
| 02_small_09.txt | AC | 3 ms | 9824 KiB |
| 02_small_10.txt | AC | 3 ms | 9828 KiB |
| 02_small_11.txt | AC | 3 ms | 9628 KiB |
| 02_small_12.txt | AC | 3 ms | 9696 KiB |
| 02_small_13.txt | AC | 3 ms | 9892 KiB |
| 02_small_14.txt | AC | 3 ms | 9696 KiB |
| 02_small_15.txt | AC | 3 ms | 9820 KiB |
| 02_small_16.txt | AC | 3 ms | 9704 KiB |
| 02_small_17.txt | AC | 3 ms | 9704 KiB |
| 02_small_18.txt | AC | 3 ms | 9816 KiB |
| 02_small_19.txt | AC | 3 ms | 9636 KiB |
| 02_small_20.txt | AC | 3 ms | 9828 KiB |
| 02_small_21.txt | AC | 3 ms | 9848 KiB |
| 02_small_22.txt | AC | 3 ms | 9728 KiB |
| 02_small_23.txt | AC | 3 ms | 9824 KiB |
| 02_small_24.txt | AC | 3 ms | 9832 KiB |
| 02_small_25.txt | AC | 3 ms | 9720 KiB |
| 03_rand_1_01.txt | AC | 216 ms | 27428 KiB |
| 03_rand_1_02.txt | AC | 211 ms | 27516 KiB |
| 03_rand_1_03.txt | AC | 221 ms | 27484 KiB |
| 03_rand_1_04.txt | AC | 209 ms | 27372 KiB |
| 03_rand_1_05.txt | AC | 210 ms | 27440 KiB |
| 04_rand_2_01.txt | AC | 190 ms | 27396 KiB |
| 04_rand_2_02.txt | AC | 190 ms | 27496 KiB |
| 04_rand_2_03.txt | AC | 163 ms | 27312 KiB |
| 04_rand_2_04.txt | AC | 182 ms | 27372 KiB |
| 04_rand_2_05.txt | AC | 173 ms | 27392 KiB |
| 04_rand_2_06.txt | AC | 193 ms | 27372 KiB |
| 04_rand_2_07.txt | AC | 198 ms | 27376 KiB |
| 04_rand_2_08.txt | AC | 193 ms | 27432 KiB |
| 04_rand_2_09.txt | AC | 196 ms | 27352 KiB |
| 04_rand_2_10.txt | AC | 197 ms | 27484 KiB |
| 05_rand_3_01.txt | AC | 146 ms | 27444 KiB |
| 05_rand_3_02.txt | AC | 137 ms | 27568 KiB |
| 05_rand_3_03.txt | AC | 126 ms | 27516 KiB |
| 05_rand_3_04.txt | AC | 126 ms | 27440 KiB |
| 05_rand_3_05.txt | AC | 159 ms | 27504 KiB |
| 05_rand_3_06.txt | AC | 157 ms | 27308 KiB |
| 05_rand_3_07.txt | AC | 149 ms | 27348 KiB |
| 05_rand_3_08.txt | AC | 152 ms | 27500 KiB |
| 05_rand_3_09.txt | AC | 188 ms | 27392 KiB |
| 05_rand_3_10.txt | AC | 173 ms | 27496 KiB |
| 06_rand_4_01.txt | AC | 159 ms | 27380 KiB |
| 06_rand_4_02.txt | AC | 156 ms | 27376 KiB |
| 06_rand_4_03.txt | AC | 157 ms | 27512 KiB |
| 06_rand_4_04.txt | AC | 175 ms | 27484 KiB |
| 06_rand_4_05.txt | AC | 126 ms | 27508 KiB |
| 06_rand_4_06.txt | AC | 183 ms | 27392 KiB |
| 06_rand_4_07.txt | AC | 148 ms | 27504 KiB |
| 06_rand_4_08.txt | AC | 139 ms | 27568 KiB |
| 06_rand_4_09.txt | AC | 167 ms | 27304 KiB |
| 06_rand_4_10.txt | AC | 155 ms | 27380 KiB |
| 07_near_998244353_01.txt | AC | 203 ms | 27372 KiB |
| 07_near_998244353_02.txt | AC | 163 ms | 27496 KiB |
| 07_near_998244353_03.txt | AC | 201 ms | 27500 KiB |
| 07_near_998244353_04.txt | AC | 204 ms | 27392 KiB |
| 07_near_998244353_05.txt | AC | 171 ms | 27388 KiB |