| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1347557 | kokokai | Skyscraper (JOI16_skyscraper) | C++20 | 75 ms | 2804 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define task "text"
int a[105];
int dp[101][1001][3],ndp[101][1001][3];
const int MOD = 1e9+7;
int add(int x,int y){
x+=y;
if(x>=MOD) x-=MOD;
return x;
}
int mul(int x,int y){
return 1LL*x*y%MOD;
}
int n,L;
int main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
}
cin>>n>>L;
for(int i=1;i<=n;i++){
cin>>a[i];
}
if(n == 1){
cout<<1<<'\n';
return 0;
}
sort(a+1,a+1+n);
dp[1][0][0]=1;
dp[1][0][1]=2;
for(int i=2;i<=n;i++){
int D=a[i]-a[i-1];
//cerr<<D<<'\n';
for(int comp=1;comp<=i;comp++){
for(int s=0;s<=L;s++){
for(int m=0;m<3;m++){
if(comp-1 >= 0){
int ns=s-D*(2*(comp-1)-m);
int nc=comp-1-1+2-m;
if(ns >= 0){
ndp[comp][s][m]=add(ndp[comp][s][m],mul(dp[comp-1][ns][m],nc));
}
}
if(comp <= i){
int ns=s-D*(2*(comp)-m);
int nc=2*comp-m;
if(ns >= 0){
ndp[comp][s][m]=add(ndp[comp][s][m],mul(dp[comp][ns][m],nc));
}
}
if(comp+1 <= i){
int ns=s-D*(2*(comp+1)-m);
int nc=comp;
if(ns >= 0){
ndp[comp][s][m]=add(ndp[comp][s][m],mul(dp[comp+1][ns][m],nc));
}
}
if(m-1 >= 0){
if(comp-1 >= 0){
int ns=s-D*(2*(comp-1)-(m-1));
int nc=2-(m-1);
if(ns>=0){
ndp[comp][s][m]=add(ndp[comp][s][m],mul(dp[comp-1][ns][m-1],nc));
}
}
if(comp <= i){
int ns=s-D*(2*(comp)-(m-1));
int nc=2-(m-1);
if(ns >= 0){
//if(comp == 1 && s == 1 && m == 2) cerr<<ns<<' '<<dp[comp][ns][m-1]<<'\n';
ndp[comp][s][m]=add(ndp[comp][s][m],mul(dp[comp][ns][m-1],nc));
}
}
}
}
}
}
//cerr<<ndp[1][1][2]<<'\n';
for(int comp=0;comp<=i;comp++){
for(int s=0;s<=L;s++){
for(int m=0;m<3;m++){
dp[comp][s][m]=ndp[comp][s][m];
ndp[comp][s][m]=0;
}
}
}
}
int ans=0;
for(int l=0;l<=L;l++){
ans=add(ans,dp[1][l][2]);
}
cout<<ans<<'\n';
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
