답안 #886541

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886541 2023-12-12T09:51:16 Z dubabuba Sandcastle 2 (JOI22_ho_t5) C++14
0 / 100
12 ms 584 KB
#include <iostream>
#include <vector>
using namespace std;

const int mxn = 1e5 + 10;
int n, m, a[mxn];

int main() {
	cin >> n >> m;
	if(n > 1) return 1;
	for(int i = 0; i < m; i++)
		cin >> a[i];

	vector<int> sus = {0};
	for(int i = 1; i < m - 1; i++) {
		if(a[i] > a[i - 1] && a[i] > a[i + 1]) sus.push_back(i);
		if(a[i] < a[i - 1] && a[i] < a[i + 1]) sus.push_back(i);
	}
	sus.push_back(m - 1);

	int ans = 0;
	for(int i = 1; i < sus.size(); i++) {
		int l = sus[i - 1];
		int r = sus[i];
		ans += (r - l + 1) * (r - l) / 2;
	}
	cout << ans + m << '\n';
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |  for(int i = 1; i < sus.size(); i++) {
      |                 ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 12 ms 584 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -