답안 #973637

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973637 2024-05-02T08:53:30 Z 8pete8 Skyscraper (JOI16_skyscraper) C++17
100 / 100
49 ms 27548 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
#include <cstdlib> 
#include <cstdint>
using namespace std;
#define ll long long
#define f first
//#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define int long long
#define double long double
const int mod=1e9+7,mxn=1e5+5,lg=60,inf=1e9,minf=-1e18,Mxn=1e6+50000;
int dp[103][103][1002][3];
int32_t main(){
	fastio
	//dp[i][num of com][cur sum][border have]
	int n,l;cin>>n>>l;
	vector<int>v(n);
	for(int i=0;i<n;i++)cin>>v[i];
	sort(all(v));
	v.pb(v.back());
	int nsum;
	if(n==1){
		cout<<1;
		return 0;
	}
	if(2*(v[1]-v[0]))dp[1][1][2*(v[1]-v[0])][0]=1;
	if(v[1]-v[0]<=l)dp[1][1][v[1]-v[0]][1]=2;
	for(int i=1;i<n;i++){
		for(int j=1;j<=n;j++){
			for(int sum=0;sum<=l;sum++){
				for(int k=0;k<3;k++){
					if(dp[i][j][sum][k]==0)continue;
					//cout<<dp[i][j][sum][k]<<" "<<i<<" "<<j<<" "<<sum<<" "<<k<<" "<<"G\n";
					//create
					nsum=(sum+((v[i+1]-v[i])*((j+1)*2-k)));
					if(nsum<=l&&nsum>=0){
						dp[i+1][j+1][nsum][k]=(dp[i+1][j+1][nsum][k]+(dp[i][j][sum][k]*(j+1-k))%mod)%mod;
					}
					//merge
					nsum=(sum+((v[i+1]-v[i])*((j-1)*2-k)));
					if(nsum<=l&&nsum>=0)dp[i+1][j-1][nsum][k]=(dp[i+1][j-1][nsum][k]+(dp[i][j][sum][k]*(j-1))%mod)%mod;
					//fill border
					//fill border by creating new one
					nsum=(sum+((v[i+1]-v[i])*(((j+1)*2)-k-1)));
					if(nsum<=l&&nsum>=0&&k+1<3){
						dp[i+1][j+1][nsum][k+1]=(dp[i+1][j+1][nsum][k+1]+(dp[i][j][sum][k]*(2-k))%mod)%mod;
					}
					/*
					missing case where
					a>b<c
					*/
					//fill border by attaching to the existing one
					nsum=(sum+(v[i+1]-v[i])*((j*2)-k-1));
					if(nsum<=l&&nsum>=0&&k+1<3){
						dp[i+1][j][nsum][k+1]=(dp[i+1][j][nsum][k+1]+(dp[i][j][sum][k]*(2-k))%mod)%mod;
					}
					//attach
					nsum=(sum+(v[i+1]-v[i])*((j*2)-k));
					if(nsum<=l&&nsum>=0)dp[i+1][j][nsum][k]=(dp[i+1][j][nsum][k]+(dp[i][j][sum][k]*((j-k)*2+k))%mod)%mod;//stick it
				}				
			}
		}
	}
	int ans=0;
	for(int i=0;i<=l;i++){
		//cout<<dp[n][1][i][2]<<" "<<i<<'\n';
		ans=(ans+dp[n][1][i][2])%mod;
	}
	cout<<ans;
	/*
	*/
	return 0;
}
/*
*/

Compilation message

skyscraper.cpp: In function 'int32_t main()':
skyscraper.cpp:54:6: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
   54 |  if(2*(v[1]-v[0]))dp[1][1][2*(v[1]-v[0])][0]=1;
      |     ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2908 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2908 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 2652 KB Output is correct
11 Correct 1 ms 2908 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2908 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 2908 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 ms 2908 KB Output is correct
20 Correct 1 ms 2652 KB Output is correct
21 Correct 2 ms 3420 KB Output is correct
22 Correct 49 ms 27548 KB Output is correct
23 Correct 41 ms 11356 KB Output is correct
24 Correct 35 ms 15668 KB Output is correct
25 Correct 40 ms 12892 KB Output is correct
26 Correct 31 ms 11856 KB Output is correct
27 Correct 22 ms 12756 KB Output is correct
28 Correct 23 ms 14936 KB Output is correct
29 Correct 40 ms 19868 KB Output is correct
30 Correct 36 ms 12880 KB Output is correct