답안 #118859

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118859 2019-06-20T00:01:50 Z tmwilliamlin168 Skyscraper (JOI16_skyscraper) C++14
100 / 100
315 ms 297208 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 1 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 1408 KB Output is correct
8 Correct 3 ms 1664 KB Output is correct
9 Correct 4 ms 2304 KB Output is correct
10 Correct 3 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 3072 KB Output is correct
2 Correct 4 ms 3456 KB Output is correct
3 Correct 5 ms 3840 KB Output is correct
4 Correct 4 ms 3328 KB Output is correct
5 Correct 4 ms 3456 KB Output is correct
6 Correct 5 ms 3840 KB Output is correct
7 Correct 4 ms 2944 KB Output is correct
8 Correct 4 ms 3840 KB Output is correct
9 Correct 5 ms 4096 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 1 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 1408 KB Output is correct
8 Correct 3 ms 1664 KB Output is correct
9 Correct 4 ms 2304 KB Output is correct
10 Correct 3 ms 1664 KB Output is correct
11 Correct 4 ms 3072 KB Output is correct
12 Correct 4 ms 3456 KB Output is correct
13 Correct 5 ms 3840 KB Output is correct
14 Correct 4 ms 3328 KB Output is correct
15 Correct 4 ms 3456 KB Output is correct
16 Correct 5 ms 3840 KB Output is correct
17 Correct 4 ms 2944 KB Output is correct
18 Correct 4 ms 3840 KB Output is correct
19 Correct 5 ms 4096 KB Output is correct
20 Correct 5 ms 3456 KB Output is correct
21 Correct 12 ms 15112 KB Output is correct
22 Correct 211 ms 193212 KB Output is correct
23 Correct 247 ms 237436 KB Output is correct
24 Correct 265 ms 271996 KB Output is correct
25 Correct 250 ms 237944 KB Output is correct
26 Correct 251 ms 243960 KB Output is correct
27 Correct 199 ms 229880 KB Output is correct
28 Correct 223 ms 247544 KB Output is correct
29 Correct 290 ms 297208 KB Output is correct
30 Correct 315 ms 237948 KB Output is correct