Compile Error
foo.cc: In function 'int main()': foo.cc:35:39: error: 'max_element' was not declared in this scope 35 | auto maxInList1 = max_element(list1.begin(), list1.end()); | ^~~~~~~~~~~ foo.cc:37:39: error: 'min_element' was not declared in this scope 37 | auto minInList2 = min_element(list2.begin(), list2.end()); | ^~~~~~~~~~~
Code
#include <iostream>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
for (int i = 1; i < n + 1; ++i) {
a[i-1] = i;
}
int count = 0;
for (int i = 0; i < n; ++i) {
for (int j = i; j < n; ++j) {
vector<int> list1;
for (int k = i; k <= j; ++k) {
list1.push_back(a[k]);
}
vector<int> list2;
for (int k = j; k >= i; --k) {
list2.push_back(a[k]);
}
if (list1.size() == list2.size()){
auto maxInList1 = max_element(list1.begin(), list1.end());
auto maxInList2 = max_element(list2.begin(), list2.end());
auto minInList2 = min_element(list2.begin(), list2.end());
auto minInList1 = min_element(list1.begin(), list1.end());
if ((maxInList1-minInList1) == (maxInList2-minInList2)){
count++;
}
}
}
}
cout << count-2 << endl;
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1052 Yet Another Array Partition
- Contest
- Brain Booster #3
- Language
- C++20 (G++ 13.2.0)
- Submit At
- 2024-05-06 16:06:15
- Judged At
- 2024-11-11 03:33:27
- Judged By
- Score
- 0
- Total Time
- 0ms
- Peak Memory
- 0 Bytes