답안 #103287

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
103287 2019-03-29T14:28:17 Z ihdignite Skyscraper (JOI16_skyscraper) C++14
100 / 100
337 ms 297428 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int mxN=100, mxM=1e3, M=1e9+7;
int n, m, a[mxN];
ll dp[mxN][4][mxN+1][mxM+1], ans;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;
	if(n<2) {
		cout << 1;
		return 0;
	}
	for(int i=0; i<n; ++i)
		cin >> a[i];
	sort(a, a+n);
	dp[0][0][1][0]=1;
	dp[0][1][1][0]=2;
	for(int i=0; i+1<n; ++i) {
		for(int j=0; j<3; ++j) {
			for(int k=1; k<n; ++k) {
				for(int l=0; l<=m; ++l) {
					int nl=l+(2*k-j)*(a[i+1]-a[i]);
					if(nl>m)
						break;
					dp[i][j][k][l]%=M;
					dp[i+1][j][k+1][nl]+=dp[i][j][k][l];
					dp[i+1][j+1][k+1][nl]+=(2-j)*dp[i][j][k][l];
					dp[i+1][j][k][nl]+=(2*k-j)*dp[i][j][k][l];
					dp[i+1][j+1][k][nl]+=(2-j)*(k-j)*dp[i][j][k][l];
					dp[i+1][j][k-1][nl]+=(k-j)*(k-1)*dp[i][j][k][l];
					if(i+2==n&&(j==1&&k==1||j==2&&k==2))
						ans+=dp[i][j][k][l];
				}
			}
		}
	}
	cout << ans%M;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:37:22: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
      if(i+2==n&&(j==1&&k==1||j==2&&k==2))
                  ~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 896 KB Output is correct
5 Correct 4 ms 1792 KB Output is correct
6 Correct 4 ms 1920 KB Output is correct
7 Correct 3 ms 1280 KB Output is correct
8 Correct 4 ms 1792 KB Output is correct
9 Correct 5 ms 2176 KB Output is correct
10 Correct 3 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3072 KB Output is correct
2 Correct 6 ms 3456 KB Output is correct
3 Correct 6 ms 3840 KB Output is correct
4 Correct 6 ms 3328 KB Output is correct
5 Correct 6 ms 3584 KB Output is correct
6 Correct 5 ms 3840 KB Output is correct
7 Correct 4 ms 2984 KB Output is correct
8 Correct 6 ms 3840 KB Output is correct
9 Correct 12 ms 3968 KB Output is correct
10 Correct 5 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 896 KB Output is correct
5 Correct 4 ms 1792 KB Output is correct
6 Correct 4 ms 1920 KB Output is correct
7 Correct 3 ms 1280 KB Output is correct
8 Correct 4 ms 1792 KB Output is correct
9 Correct 5 ms 2176 KB Output is correct
10 Correct 3 ms 1536 KB Output is correct
11 Correct 5 ms 3072 KB Output is correct
12 Correct 6 ms 3456 KB Output is correct
13 Correct 6 ms 3840 KB Output is correct
14 Correct 6 ms 3328 KB Output is correct
15 Correct 6 ms 3584 KB Output is correct
16 Correct 5 ms 3840 KB Output is correct
17 Correct 4 ms 2984 KB Output is correct
18 Correct 6 ms 3840 KB Output is correct
19 Correct 12 ms 3968 KB Output is correct
20 Correct 5 ms 3456 KB Output is correct
21 Correct 15 ms 15104 KB Output is correct
22 Correct 270 ms 193132 KB Output is correct
23 Correct 280 ms 237412 KB Output is correct
24 Correct 300 ms 272032 KB Output is correct
25 Correct 306 ms 238072 KB Output is correct
26 Correct 259 ms 243960 KB Output is correct
27 Correct 212 ms 229992 KB Output is correct
28 Correct 256 ms 247532 KB Output is correct
29 Correct 337 ms 297428 KB Output is correct
30 Correct 313 ms 237816 KB Output is correct