-
Notifications
You must be signed in to change notification settings - Fork 0
/
ALTSEQ.cpp
90 lines (76 loc) · 1.16 KB
/
ALTSEQ.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <vector>
#include "limits.h"
using namespace std;
typedef long long LL;
class ALTSEQ
{
public:
int Solve(vector<LL> array);
};
bool isToggle(LL a, LL b){
if(a < 0 && b >= 0){
return true;
}
else if (a >= 0 && b < 0)
{
return true;
}
return false;
}
LL myabs(LL a){
if (a < 0)
{
return -a;
}
return a;
}
LL mymax(LL a, LL b){
if (a > b)
{
return a;
}
return b;
}
int ALTSEQ::Solve(vector<LL> array){
int* DP = new int[array.size()];
for (int i = 0; i < array.size(); ++i)
{
DP[i] = 1;
}
for (int i = 1; i < array.size(); ++i)
{
for (int j = 0; j < i; ++j)
{
if (myabs(array[i]) > myabs(array[j]) && isToggle(array[i], array[j]))
{
DP[i] = mymax(DP[i], DP[j]+1);
}
}
}
// for (int i = 0; i < array.size(); ++i)
// {
// cout << DP[i] << " ";
// }
int answer = 1;
for (int i = 0; i < array.size(); ++i)
{
answer = mymax(answer, DP[i]);
}
return answer;
}
int main(int argc, char const *argv[])
{
int N;
cin >> N;
LL x;
std::vector<LL> vecc;
for (int i = 0; i < N; ++i)
{
cin >> x;
vecc.push_back(x);
}
ALTSEQ mach;
cout << mach.Solve(vecc) << endl;
return 0;
}