답안 #1055181

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1055181 2024-08-12T15:06:17 Z parsadox2 Sparklers (JOI17_sparklers) C++17
50 / 100
69 ms 20692 KB
#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;

const int N = 1e3 + 10;
int n , a[N] , k , t , sum[N][N] , x[N];
vector <int> A , B;
bool marked[N][N];

bool check(int mid)
{
	for(int i = 0 ; i < A.size() ; i++)
		A[i] -= 2LL * mid * t;
	for(int i = 0 ; i < B.size() ; i++)
		B[i] -= 2LL * mid * t;

	for(int i = 0 ; i <= A.size() ; i++)
	{
		sum[i][0] = 0;
		if(i > 0)
			sum[i][0] = A[i - 1] + sum[i - 1][0];
		marked[i][0] = false;
		for(int j = 1 ; j <= B.size() ; j++)
		{
			marked[i][j] = false;
			sum[i][j] = sum[i][j - 1] + B[j - 1];
		}
	}
	queue <pair<int ,int>> q;
	marked[0][0] = true;
	q.push(make_pair(0 , 0));
	while(!q.empty())
	{
		auto now = q.front();  q.pop();
		if(now.F != A.size() && sum[now.F + 1][now.S] <= 0 && !marked[now.F + 1][now.S])
		{
			marked[now.F + 1][now.S] = true;
			q.push({now.F + 1 , now.S});
		}
		if(now.S != B.size() && sum[now.F][now.S + 1] <= 0 && !marked[now.F][now.S + 1])
		{
			marked[now.F][now.S + 1] = true;
			q.push({now.F , now.S + 1});
		}
	}
	for(int i = 0 ; i < A.size() ; i++)
		A[i] += 2LL * mid * t;
	for(int i = 0 ; i < B.size() ; i++)
		B[i] += 2LL * mid * t;
	return marked[A.size()][B.size()];
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);  cout.tie(0);
	cin >> n >> k >> t;
	for(int i = 1 ; i <= n ; i++)
		cin >> x[i];
	for(int i = 1 ; i + 1 <= k ; i++)
		A.push_back(x[i + 1] - x[i]);
	for(int i = k ; i + 1 <= n ; i++)
		B.push_back(x[i + 1] - x[i]);
	reverse(A.begin() , A.end());
	int low = -1 , high = 2e9 / t;
	while(high - low > 1)
	{
		int mid = (low + high) >> 1;
		if(check(mid))
			high = mid;
		else
			low = mid;
	}
	cout << high << '\n';
	return 0;
}

Compilation message

sparklers.cpp: In function 'bool check(long long int)':
sparklers.cpp:14:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i = 0 ; i < A.size() ; i++)
      |                  ~~^~~~~~~~~~
sparklers.cpp:16:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  for(int i = 0 ; i < B.size() ; i++)
      |                  ~~^~~~~~~~~~
sparklers.cpp:19:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for(int i = 0 ; i <= A.size() ; i++)
      |                  ~~^~~~~~~~~~~
sparklers.cpp:25:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   for(int j = 1 ; j <= B.size() ; j++)
      |                   ~~^~~~~~~~~~~
sparklers.cpp:37:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   if(now.F != A.size() && sum[now.F + 1][now.S] <= 0 && !marked[now.F + 1][now.S])
      |      ~~~~~~^~~~~~~~~~~
sparklers.cpp:42:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   if(now.S != B.size() && sum[now.F][now.S + 1] <= 0 && !marked[now.F][now.S + 1])
      |      ~~~~~~^~~~~~~~~~~
sparklers.cpp:48:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  for(int i = 0 ; i < A.size() ; i++)
      |                  ~~^~~~~~~~~~
sparklers.cpp:50:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for(int i = 0 ; i < B.size() ; i++)
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 25 ms 4696 KB Output is correct
23 Correct 16 ms 4772 KB Output is correct
24 Correct 7 ms 2396 KB Output is correct
25 Correct 4 ms 2396 KB Output is correct
26 Correct 29 ms 2660 KB Output is correct
27 Correct 35 ms 4696 KB Output is correct
28 Correct 52 ms 6744 KB Output is correct
29 Correct 54 ms 6744 KB Output is correct
30 Correct 35 ms 8792 KB Output is correct
31 Correct 44 ms 8796 KB Output is correct
32 Correct 55 ms 6744 KB Output is correct
33 Correct 58 ms 6748 KB Output is correct
34 Correct 29 ms 8860 KB Output is correct
35 Correct 54 ms 8796 KB Output is correct
36 Correct 18 ms 2396 KB Output is correct
37 Correct 17 ms 2396 KB Output is correct
38 Correct 50 ms 8864 KB Output is correct
39 Correct 12 ms 8932 KB Output is correct
40 Correct 69 ms 4756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 25 ms 4696 KB Output is correct
23 Correct 16 ms 4772 KB Output is correct
24 Correct 7 ms 2396 KB Output is correct
25 Correct 4 ms 2396 KB Output is correct
26 Correct 29 ms 2660 KB Output is correct
27 Correct 35 ms 4696 KB Output is correct
28 Correct 52 ms 6744 KB Output is correct
29 Correct 54 ms 6744 KB Output is correct
30 Correct 35 ms 8792 KB Output is correct
31 Correct 44 ms 8796 KB Output is correct
32 Correct 55 ms 6744 KB Output is correct
33 Correct 58 ms 6748 KB Output is correct
34 Correct 29 ms 8860 KB Output is correct
35 Correct 54 ms 8796 KB Output is correct
36 Correct 18 ms 2396 KB Output is correct
37 Correct 17 ms 2396 KB Output is correct
38 Correct 50 ms 8864 KB Output is correct
39 Correct 12 ms 8932 KB Output is correct
40 Correct 69 ms 4756 KB Output is correct
41 Runtime error 45 ms 20692 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -