답안 #61148

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
61148 2018-07-25T08:59:37 Z Eae02 Boat (APIO16_boat) C++14
9 / 100
156 ms 174564 KB
#include <bits/stdc++.h>
	
uint64_t PRIME = 1000000007;
	
std::vector<std::pair<uint64_t, uint64_t>> schools;
	
std::unordered_map<uint64_t, uint64_t> memo[500];
	
uint64_t count(int i, uint64_t min)
{
	if (i >= schools.size())
		return 1;
	auto mIt = memo[i].find(min);
	if (mIt != memo[i].end())
		return mIt->second;
	
	uint64_t c = count(i + 1, min);
	for (uint64_t n = std::max(schools[i].first, min == 0 ? 0 : (min + 1)); n <= schools[i].second; n++)
	{
		c = (c + count(i + 1, n)) % PRIME;
	}
	
	memo[i].insert(std::make_pair(min, c));
	return c;
}
	
int main()
{
	int N;
	std::cin >> N;
	
	bool allSame = true;
	uint64_t max2 = 0;
	
	schools.resize(N);
	for (int i = 0; i < N; i++)
	{
		std::cin >> schools[i].first;
		std::cin >> schools[i].second;
		if (schools[i].first != schools[i].second)
			allSame = false;
		max2 = std::max(max2, schools[i].second);
	}
	
	if (allSame)
	{
		std::cout << (count(0, 0) - 1) << std::endl;
	}
	else
	{
		std::vector<uint64_t> waysElim(max2 + 1);
		uint64_t ways = 1;
		for (int i = 0; i < N; i++)
		{
			const uint64_t prevWays = ways;
			
			const uint64_t d = schools[i].second - schools[i].first + 1;
			ways = (ways * ((d + 1) % PRIME)) % PRIME;
			
			for (uint64_t j = 0; j < d; j++)
			{
				uint64_t eI = schools[i].second - j;
				ways -= waysElim[eI];
				waysElim[eI] = (j + 1) * prevWays - waysElim[eI];
			}
			
			//for (uint64_t w : waysElim)
			//	std::cout << " " << w;
			//std::cout << std::endl;
		}
		std::cout << ways - 1 << std::endl;
	}
}

Compilation message

boat.cpp: In function 'uint64_t count(int, uint64_t)':
boat.cpp:11:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (i >= schools.size())
      ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 5880 KB Output is correct
2 Correct 63 ms 5988 KB Output is correct
3 Correct 58 ms 5988 KB Output is correct
4 Correct 54 ms 6016 KB Output is correct
5 Correct 53 ms 6016 KB Output is correct
6 Correct 60 ms 6016 KB Output is correct
7 Correct 63 ms 6216 KB Output is correct
8 Correct 52 ms 6216 KB Output is correct
9 Correct 49 ms 6216 KB Output is correct
10 Correct 73 ms 6216 KB Output is correct
11 Correct 51 ms 6216 KB Output is correct
12 Correct 54 ms 6216 KB Output is correct
13 Correct 59 ms 6216 KB Output is correct
14 Correct 67 ms 6216 KB Output is correct
15 Correct 48 ms 6216 KB Output is correct
16 Correct 12 ms 6216 KB Output is correct
17 Correct 16 ms 6216 KB Output is correct
18 Correct 13 ms 6216 KB Output is correct
19 Correct 14 ms 6216 KB Output is correct
20 Correct 15 ms 6216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 5880 KB Output is correct
2 Correct 63 ms 5988 KB Output is correct
3 Correct 58 ms 5988 KB Output is correct
4 Correct 54 ms 6016 KB Output is correct
5 Correct 53 ms 6016 KB Output is correct
6 Correct 60 ms 6016 KB Output is correct
7 Correct 63 ms 6216 KB Output is correct
8 Correct 52 ms 6216 KB Output is correct
9 Correct 49 ms 6216 KB Output is correct
10 Correct 73 ms 6216 KB Output is correct
11 Correct 51 ms 6216 KB Output is correct
12 Correct 54 ms 6216 KB Output is correct
13 Correct 59 ms 6216 KB Output is correct
14 Correct 67 ms 6216 KB Output is correct
15 Correct 48 ms 6216 KB Output is correct
16 Correct 12 ms 6216 KB Output is correct
17 Correct 16 ms 6216 KB Output is correct
18 Correct 13 ms 6216 KB Output is correct
19 Correct 14 ms 6216 KB Output is correct
20 Correct 15 ms 6216 KB Output is correct
21 Incorrect 156 ms 174564 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 174564 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 5880 KB Output is correct
2 Correct 63 ms 5988 KB Output is correct
3 Correct 58 ms 5988 KB Output is correct
4 Correct 54 ms 6016 KB Output is correct
5 Correct 53 ms 6016 KB Output is correct
6 Correct 60 ms 6016 KB Output is correct
7 Correct 63 ms 6216 KB Output is correct
8 Correct 52 ms 6216 KB Output is correct
9 Correct 49 ms 6216 KB Output is correct
10 Correct 73 ms 6216 KB Output is correct
11 Correct 51 ms 6216 KB Output is correct
12 Correct 54 ms 6216 KB Output is correct
13 Correct 59 ms 6216 KB Output is correct
14 Correct 67 ms 6216 KB Output is correct
15 Correct 48 ms 6216 KB Output is correct
16 Correct 12 ms 6216 KB Output is correct
17 Correct 16 ms 6216 KB Output is correct
18 Correct 13 ms 6216 KB Output is correct
19 Correct 14 ms 6216 KB Output is correct
20 Correct 15 ms 6216 KB Output is correct
21 Incorrect 156 ms 174564 KB Output isn't correct
22 Halted 0 ms 0 KB -