ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#186690 | #3353. 雨落玫瑰 | Alan_Zhaoyz | 100 | 6028ms | 1904kb | C++11 | 1.9kb | 2023-10-01 11:17:41 | 2023-10-01 12:41:14 |
answer
// 都什么年代了还 g++5 啊??????
#include <bits/stdc++.h>
using namespace std;
#define For(Ti,Ta,Tb) for(auto Ti=(Ta);Ti<=(Tb);++Ti)
#define Dec(Ti,Ta,Tb) for(auto Ti=(Ta);Ti>=(Tb);--Ti)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define range(Tx) begin(Tx),end(Tx)
using ll=long long;
const int N=2.5e4+5,K=27,Mod=1e9+7;
using Info=array<array<int,2>,K>;
int n,k,h[N],id[N],h_[N];
Info dp(const vector<int>& hs,int k){
Info f[2][K]{};
int par=0;
f[0][0][0][0]=1;
vector<int> vec;
auto get=[&](int x){
return lower_bound(range(vec),x,greater<int>())-vec.begin()+1;
};
for(int x:hs){
static int real[K],nxt[K];
real[0]=0;
For(i,1,min(int(vec.size()),k+1)){
real[i]=vec[i-1];
}
vec.insert(vec.begin()+(get(x)-1),x);
For(i,1,min(int(vec.size())-1,k+1)){
nxt[i]=get(real[i]);
}
int getx=get(x);
For(a,0,k+1){
For(b,0,k){
For(c,0,1){
ll F=f[par][a][b][c];
if(!F) continue;
if(b<k&&x){
(f[par^1][nxt[a]][b+1][c^(real[a]&1)]+=F)%=Mod;
}
(f[par^1][real[a]>=x?nxt[a]:getx][b][c^(max(real[a]-x,0)&1)]+=F)%=Mod;
}
}
}
memset(f[par],0,sizeof(f[par]));
par^=1;
}
Info ans{};
For(a,0,k+1){
For(b,0,k){
For(c,0,1){
(ans[b][c]+=f[par][a][b][c])%=Mod;
}
}
}
return ans;
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin>>n>>k;
For(i,1,n){
cin>>h[i];
h_[i]=h[i];
id[i]=i;
}
sort(id+1,id+n+1,[](int i,int j){
return h[i]>h[j];
});
ll ans=0;
For(i,1,k+1){
For(j,1,i-1) h[id[j]]=0;
vector<int> v1,v2;
For(j,1,id[i]-1){
v1.push_back(h[j]);
}
Dec(j,n,id[i]+1){
v2.push_back(h[j]);
}
auto f1=dp(v1,k-i+1),f2=dp(v2,k-i+1);
For(b,0,k-i+1){
For(c,0,1){
(ans+=1LL*f1[b][c]*f2[k-i+1-b][c])%=Mod;
}
}
For(j,1,n) h[j]=h_[j];
}
cout<<ans<<'\n';
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1284kb
input:
20 10 17555697 225663153 267317961 109938115 578806141 659739421 597281665 103951030 285251051 66543...
output:
92314
result:
ok 1 number(s): "92314"
Test #2:
score: 10
Accepted
time: 17ms
memory: 1668kb
input:
20000 0 1447384 235371887 294560601 544621393 134982757 130696357 35748139 445921103 333479259 46356...
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 10
Accepted
time: 12ms
memory: 1288kb
input:
200 25 89405029 287841877 279147241 435182157 291231117 583624158 124125093 54923855 62173677 513305...
output:
420252466
result:
ok 1 number(s): "420252466"
Test #4:
score: 10
Accepted
time: 13ms
memory: 1292kb
input:
200 25 162098041 280130852 358612462 669241371 668611901 349053517 320595801 9356986 618973861 25689...
output:
883879813
result:
ok 1 number(s): "883879813"
Test #5:
score: 10
Accepted
time: 12ms
memory: 1288kb
input:
200 25 493903079 7288021 24327301 452516569 431951051 380381122 434128029 2483206 369058649 25886995...
output:
938347802
result:
ok 1 number(s): "938347802"
Test #6:
score: 10
Accepted
time: 65ms
memory: 1320kb
input:
1000 25 53675497 34703857 313369933 338081551 640372541 826017 852172048 11684239 570907231 15305318...
output:
220588771
result:
ok 1 number(s): "220588771"
Test #7:
score: 10
Accepted
time: 64ms
memory: 1316kb
input:
1000 25 585518166 289776964 22499577 79354617 868796353 116628083 88604314 51980500 92341116 4088509...
output:
207083490
result:
ok 1 number(s): "207083490"
Test #8:
score: 10
Accepted
time: 1962ms
memory: 1904kb
input:
25000 25 40306211 14787586 603428261 114843202 281743995 94890062 11251486 134541699 151076551 81962...
output:
706405307
result:
ok 1 number(s): "706405307"
Test #9:
score: 10
Accepted
time: 1925ms
memory: 1848kb
input:
25000 25 5913979 64575752 351952756 379776557 45242326 182872419 150007411 24063937 123538621 134891...
output:
694164021
result:
ok 1 number(s): "694164021"
Test #10:
score: 10
Accepted
time: 1958ms
memory: 1860kb
input:
25000 25 20176450 442815539 515507510 119624479 64047196 431741587 28989112 585526096 43950731 36846...
output:
473111641
result:
ok 1 number(s): "473111641"
Extra Test:
score: 0
Extra Test Passed