답안 #242325

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242325 2020-06-27T08:52:46 Z shenxy 3단 점프 (JOI19_jumps) C++11
32 / 100
4000 ms 7016 KB
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int, int> ii;
int main() {
	int N, Q, L, R;
	scanf("%d", &N);
	int A[N];
	for (int i = 0; i < N; ++i) scanf("%d", &A[i]);
	scanf("%d", &Q);
	if (Q == 1) {
		scanf("%d %d", &L, &R);
		--L, --R;
		vector<int> st;
		vector<ii> gps;
		for (int i = L; i <= R; ++i) {
			while (!st.empty() && A[st.back()] <= A[i]) gps.push_back(ii(st.back(), i)), st.pop_back();
			if (!st.empty()) gps.push_back(ii(st.back(), i));
			st.push_back(i);
		}
		int ans = 0, SA[R - L + 1];
		SA[R - L] = A[R];
		for (int i = R - 1; i >= L; --i) SA[i - L] = max(SA[i - L + 1], A[i]);
		for (ii i: gps) {
			if (2 * i.second - i.first - L <= R) ans = max(ans, A[i.first] + A[i.second] + SA[2 * i.second - i.first - L]);
		}
		printf("%d", ans);
		return 0;
	}
	for (int i = 0; i < Q; ++i) {
		scanf("%d %d", &L, &R);
		--L, --R;
		int ans = 0;
		for (int i = L; i <= R; ++i) {
			for (int j = i + 1; j <= R; ++j) {
				for (int k = j + j - i; k <= R; ++k) ans = max(ans, A[i] + A[j] + A[k]);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Compilation message

jumps.cpp: In function 'int main()':
jumps.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
jumps.cpp:10:35: 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", &A[i]);
                              ~~~~~^~~~~~~~~~~~~
jumps.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
  ~~~~~^~~~~~~~~~
jumps.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &L, &R);
   ~~~~~^~~~~~~~~~~~~~~~~
jumps.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &L, &R);
   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Correct 6 ms 256 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 256 KB Output is correct
6 Correct 6 ms 256 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 256 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Correct 6 ms 256 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 256 KB Output is correct
6 Correct 6 ms 256 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 256 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Execution timed out 4067 ms 384 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 5352 KB Output is correct
2 Correct 37 ms 3560 KB Output is correct
3 Correct 39 ms 5224 KB Output is correct
4 Correct 48 ms 7016 KB Output is correct
5 Correct 46 ms 7016 KB Output is correct
6 Correct 42 ms 6376 KB Output is correct
7 Correct 41 ms 6248 KB Output is correct
8 Correct 41 ms 6376 KB Output is correct
9 Correct 44 ms 6632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Correct 6 ms 256 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 6 ms 256 KB Output is correct
6 Correct 6 ms 256 KB Output is correct
7 Correct 6 ms 256 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 256 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Execution timed out 4067 ms 384 KB Time limit exceeded
12 Halted 0 ms 0 KB -