답안 #91043

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91043 2018-12-26T00:14:52 Z tincamatei Skyscraper (JOI16_skyscraper) C++14
100 / 100
225 ms 47800 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 100;
const int MAX_L = 1000;
const int MOD = 1000000007;
int v[1+MAX_N];

int dp[1+MAX_N][1+MAX_N+1][1+MAX_L][3];

int main() {
#ifdef HOME
	FILE *fin = fopen("input.in", "r");
	FILE *fout = fopen("output.out", "w");
#else
	FILE *fin = stdin;
	FILE *fout = stdout;
#endif

	int n, l;

	fscanf(fin, "%d%d", &n, &l);
	
	for(int i = 1; i <= n; ++i)
		fscanf(fin, "%d", &v[i]);
	sort(v + 1, v + 1 + n);

	if(n == 1) {
		fprintf(fout, "%d", 1);
	} else {
		dp[0][0][0][0] = 1;
		for(int N = 1; N <= n; ++N)
			for(int C = 1; C <= N; ++C)
				for(int L = 0; L <= l; ++L)
					for(int E = 0; E <= 2; ++E) {
						int scad;

						// Componenta noua:
						scad = ((C - 1) * 2 - E) * (v[N] - v[N - 1]);
						if(L >= scad)
							dp[N][C][L][E] = ((long long)dp[N - 1][C - 1][L - scad][E] * (C - E) + dp[N][C][L][E]) % MOD;
						
						// Atasez la o componenta
						scad = (C * 2 - E) * (v[N] - v[N - 1]);
						if(L >= scad)
							dp[N][C][L][E] = ((long long)dp[N - 1][C][L - scad][E] * (C * 2 - E) + dp[N][C][L][E]) % MOD;
						
						// Unesc doua componente
						scad = ((C + 1) * 2 - E) * (v[N] - v[N - 1]);
						if(L >= scad)
							dp[N][C][L][E] = ((long long)dp[N - 1][C + 1][L - scad][E] * C + dp[N][C][L][E]) % MOD;
						
						// Imi creez o componenta intr-o margine
						scad = ((C - 1) * 2 - (E - 1)) * (v[N] - v[N - 1]);
						if(L >= scad && E >= 1)
							dp[N][C][L][E] = ((long long)dp[N - 1][C - 1][L - scad][E - 1] * (2 - E + 1) + dp[N][C][L][E]) % MOD;
						
						// Atasez la o componenta si fixez marginea
						scad = (2 * C - (E - 1)) * (v[N] - v[N - 1]);
						if(L >= scad && E >= 1)
							dp[N][C][L][E] = ((long long)dp[N - 1][C][L - scad][E - 1] * (2 - E + 1) + dp[N][C][L][E]) % MOD;
					}
		
		int rez = 0;
		for(int i = 0; i <= l; ++i)
			rez = (rez + dp[n][1][i][2]) % MOD;
		fprintf(fout, "%d", rez % MOD);
	}
#ifdef HOME
	fclose(fin);
	fclose(fout);
#endif
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:23:8: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  fscanf(fin, "%d%d", &n, &l);
  ~~~~~~^~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:26:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   fscanf(fin, "%d", &v[i]);
   ~~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 476 KB Output is correct
3 Correct 2 ms 476 KB Output is correct
4 Correct 2 ms 476 KB Output is correct
5 Correct 3 ms 840 KB Output is correct
6 Correct 3 ms 840 KB Output is correct
7 Correct 2 ms 840 KB Output is correct
8 Correct 2 ms 840 KB Output is correct
9 Correct 3 ms 888 KB Output is correct
10 Correct 2 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 972 KB Output is correct
2 Correct 2 ms 1004 KB Output is correct
3 Correct 2 ms 1020 KB Output is correct
4 Correct 2 ms 1024 KB Output is correct
5 Correct 3 ms 1024 KB Output is correct
6 Correct 2 ms 1024 KB Output is correct
7 Correct 2 ms 1024 KB Output is correct
8 Correct 2 ms 1024 KB Output is correct
9 Correct 3 ms 1148 KB Output is correct
10 Correct 2 ms 1148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 476 KB Output is correct
3 Correct 2 ms 476 KB Output is correct
4 Correct 2 ms 476 KB Output is correct
5 Correct 3 ms 840 KB Output is correct
6 Correct 3 ms 840 KB Output is correct
7 Correct 2 ms 840 KB Output is correct
8 Correct 2 ms 840 KB Output is correct
9 Correct 3 ms 888 KB Output is correct
10 Correct 2 ms 888 KB Output is correct
11 Correct 2 ms 972 KB Output is correct
12 Correct 2 ms 1004 KB Output is correct
13 Correct 2 ms 1020 KB Output is correct
14 Correct 2 ms 1024 KB Output is correct
15 Correct 3 ms 1024 KB Output is correct
16 Correct 2 ms 1024 KB Output is correct
17 Correct 2 ms 1024 KB Output is correct
18 Correct 2 ms 1024 KB Output is correct
19 Correct 3 ms 1148 KB Output is correct
20 Correct 2 ms 1148 KB Output is correct
21 Correct 5 ms 3324 KB Output is correct
22 Correct 162 ms 36860 KB Output is correct
23 Correct 219 ms 43996 KB Output is correct
24 Correct 195 ms 46952 KB Output is correct
25 Correct 225 ms 46952 KB Output is correct
26 Correct 198 ms 46952 KB Output is correct
27 Correct 86 ms 46952 KB Output is correct
28 Correct 107 ms 46952 KB Output is correct
29 Correct 181 ms 47800 KB Output is correct
30 Correct 223 ms 47800 KB Output is correct