Submission #1042327

# Submission time Handle Problem Language Result Execution time Memory
1042327 2024-08-02T21:15:15 Z 1L1YA Skyscraper (JOI16_skyscraper) C++17
100 / 100
48 ms 5468 KB
//1L1YA

#include<bits/stdc++.h>
using namespace std;

#pragma GCC optimize ("O3,unrool-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

typedef long long       ll;
typedef pair<ll,ll>     pll;
typedef pair<int,int>   pii;

#define Pb              push_back
#define F               first
#define S               second
#define endl            '\n'
#define sep             ' '
#define all(x)          x.begin(),x.end()
#define al(x,n)         x+1,x+n+1
#define SZ(x)           ((int)x.size())
#define lc              (id<<1)
#define rc              (lc|1)
#define mid             (l+r>>1)
#define dokme(x)        cout << x << endl, exit(0)
#define sik(x)          cout << x << endl;continue;
#define FastIO          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FileIO          freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll oo=1e18;
const int mod=1e9+7;
const int inf=1e9+111;
const int N=111;
const int M=1011;
const int lg=23;

ll n,m,a[N],dp[M][N][3],DP[M][N][3];

int main(){
	FastIO

	cin >> n >> m;
	for(int i=1;i<=n;i++)	cin >> a[i];
	if(n==1)	dokme(1);
	sort(al(a,n));
	DP[0][0][0]=1;
	a[n+1]=1e5;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=m;j++)
			for(int k=1;k<=i;k++)
				for(int c=0;c<3;c++){
					int p=2*k-c,w=j-p*(a[i+1]-a[i]);
					dp[j][k][c]=0;
					if(w<0)	continue;
					dp[j][k][c]=(DP[w][k-1][c]*(k-c)+DP[w][k][c]*p+DP[w][k+1][c]*k)%mod;
					if(c)	dp[j][k][c]=(dp[j][k][c]+DP[w][k-1][c-1]*(3-c)+DP[w][k][c-1]*(3-c))%mod;
				}
		for(int j=0;j<=m;j++)
			for(int k=0;k<=i;k++)
				for(int c=0;c<3;c++)
					DP[j][k][c]=dp[j][k][c];
	}
	ll ans=0;
	for(int i=0;i<=m;i++)	ans=(ans+dp[i][1][2])%mod;
	cout << ans << endl;

	return 0;
}

Compilation message

skyscraper.cpp:6:40: warning: bad option '-funrool-loops' to pragma 'optimize' [-Wpragmas]
    6 | #pragma GCC optimize ("O3,unrool-loops")
      |                                        ^
skyscraper.cpp:40:10: warning: bad option '-funrool-loops' to attribute 'optimize' [-Wattributes]
   40 | int main(){
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2652 KB Output is correct
5 Correct 2 ms 5212 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 0 ms 860 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 856 KB Output is correct
5 Correct 0 ms 2776 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2652 KB Output is correct
5 Correct 2 ms 5212 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 1 ms 1116 KB Output is correct
8 Correct 0 ms 860 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 1 ms 860 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 856 KB Output is correct
15 Correct 0 ms 2776 KB Output is correct
16 Correct 1 ms 860 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 1 ms 860 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 34 ms 4696 KB Output is correct
23 Correct 47 ms 5468 KB Output is correct
24 Correct 41 ms 4188 KB Output is correct
25 Correct 47 ms 5464 KB Output is correct
26 Correct 42 ms 4700 KB Output is correct
27 Correct 13 ms 2904 KB Output is correct
28 Correct 17 ms 3164 KB Output is correct
29 Correct 33 ms 3932 KB Output is correct
30 Correct 48 ms 5464 KB Output is correct