답안 #111417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
111417 2019-05-15T10:34:56 Z ecasdqina Boat (APIO16_boat) C++14
31 / 100
1543 ms 525312 KB
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n), b(n);
	for(int i = 0; i < n; i++) scanf("%d%d", &a[i], &b[i]);
	
	const int MOD = 1e9 + 7;
	auto dp = make_v<i64>(n + 1, 0); dp[0].resize(1, 1);
	auto sub = make_v<i64>(n + 1, 0); sub[0].resize(2, 0); sub[0][1] = 1;
	for(int i = 0; i < n; i++) {
		dp[i + 1].resize(b[i] - a[i] + 1, 0);
		sub[i + 1].resize(b[i] - a[i] + 2, 0);
		for(int j = 0; j < i + 1; j++) {
			for(int k = a[i]; k < b[i] + 1; k++) {
				if(j and k < a[j - 1]) continue;
				int ind = 0;
				if(j) ind = std::min((int)dp[j].size(), k - a[j - 1]);
				else ind = 1;
				
				(dp[i + 1][k - a[i]] += sub[j][ind]) %= MOD;
			}
		}
		for(int j = 0; j < dp[i + 1].size(); j++) sub[i + 1][j + 1] = (sub[i + 1][j] + dp[i + 1][j]) % MOD;
	
	//	for(auto v: dp[i + 1]) cout << v << " "; cout << endl;
	//	for(auto v: sub[i + 1]) cout << v << " "; cout << endl;
	}
	
	i64 ans = 0;
	for(int i = 1; i < dp.size(); i++) for(int j = 0; j < dp[i].size(); j++) (ans += dp[i][j]) %= MOD;
	printf("%lld\n", ans);
	return 0;
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:36:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j < dp[i + 1].size(); j++) sub[i + 1][j + 1] = (sub[i + 1][j] + dp[i + 1][j]) % MOD;
                  ~~^~~~~~~~~~~~~~~~~~
boat.cpp:43:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < dp.size(); i++) for(int j = 0; j < dp[i].size(); j++) (ans += dp[i][j]) %= MOD;
                 ~~^~~~~~~~~~~
boat.cpp:43:54: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 1; i < dp.size(); i++) for(int j = 0; j < dp[i].size(); j++) (ans += dp[i][j]) %= MOD;
                                                    ~~^~~~~~~~~~~~~~
boat.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n; scanf("%d", &n); std::vector<int> a(n), b(n);
         ~~~~~^~~~~~~~~~
boat.cpp:18:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < n; i++) scanf("%d%d", &a[i], &b[i]);
                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 791 ms 14084 KB Output is correct
22 Correct 669 ms 14004 KB Output is correct
23 Correct 646 ms 13400 KB Output is correct
24 Correct 700 ms 14584 KB Output is correct
25 Correct 711 ms 14780 KB Output is correct
26 Correct 973 ms 15480 KB Output is correct
27 Correct 1107 ms 16020 KB Output is correct
28 Correct 1060 ms 15696 KB Output is correct
29 Correct 1267 ms 15836 KB Output is correct
30 Correct 1543 ms 16120 KB Output is correct
31 Correct 1272 ms 15900 KB Output is correct
32 Correct 1416 ms 16040 KB Output is correct
33 Correct 1233 ms 15668 KB Output is correct
34 Correct 1395 ms 15680 KB Output is correct
35 Correct 635 ms 15100 KB Output is correct
36 Correct 818 ms 15608 KB Output is correct
37 Correct 780 ms 15736 KB Output is correct
38 Correct 686 ms 15224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 378 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 791 ms 14084 KB Output is correct
22 Correct 669 ms 14004 KB Output is correct
23 Correct 646 ms 13400 KB Output is correct
24 Correct 700 ms 14584 KB Output is correct
25 Correct 711 ms 14780 KB Output is correct
26 Correct 973 ms 15480 KB Output is correct
27 Correct 1107 ms 16020 KB Output is correct
28 Correct 1060 ms 15696 KB Output is correct
29 Correct 1267 ms 15836 KB Output is correct
30 Correct 1543 ms 16120 KB Output is correct
31 Correct 1272 ms 15900 KB Output is correct
32 Correct 1416 ms 16040 KB Output is correct
33 Correct 1233 ms 15668 KB Output is correct
34 Correct 1395 ms 15680 KB Output is correct
35 Correct 635 ms 15100 KB Output is correct
36 Correct 818 ms 15608 KB Output is correct
37 Correct 780 ms 15736 KB Output is correct
38 Correct 686 ms 15224 KB Output is correct
39 Runtime error 378 ms 525312 KB Execution killed with signal 9 (could be triggered by violating memory limits)
40 Halted 0 ms 0 KB -