質問編集履歴
1
自分の書いたコードを追加しました。これでよかったでしょうか?
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,9 +22,119 @@
|
|
22
22
|
|
23
23
|
### 該当のソースコード
|
24
24
|
|
25
|
+
```C++
|
26
|
+
|
27
|
+
#include <iostream>
|
28
|
+
|
29
|
+
using namespace std;
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
void happiness(int cnt);
|
34
|
+
|
35
|
+
int** pHappiness;
|
36
|
+
|
37
|
+
int* pGroup;
|
38
|
+
|
39
|
+
long long* pHappy;
|
40
|
+
|
41
|
+
long long ans;
|
42
|
+
|
43
|
+
int N;
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
void Happiness(int cnt){
|
48
|
+
|
49
|
+
int preHappy;
|
50
|
+
|
51
|
+
for(int i = 0; i < 3; ++i){
|
52
|
+
|
53
|
+
pGroup[cnt] = i;
|
54
|
+
|
55
|
+
if(cnt == 0) *pHappy = 0;
|
56
|
+
|
57
|
+
if(i == 0) preHappy = 0;
|
58
|
+
|
59
|
+
else *pHappy = *pHappy - preHappy;
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
for(int j = 0; j < cnt; ++j){
|
64
|
+
|
65
|
+
if(pGroup[j] == pGroup[cnt]) preHappy += pHappiness[j][cnt-1];
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
*pHappy += preHappy;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
if(cnt < N-1){
|
74
|
+
|
75
|
+
Happiness(cnt+1);
|
76
|
+
|
77
|
+
}else{
|
78
|
+
|
79
|
+
if(ans < *pHappy) ans = *pHappy;
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
*pHappy -= preHappy;
|
86
|
+
|
87
|
+
return;
|
88
|
+
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
int main(void){
|
94
|
+
|
95
|
+
cin >> N;
|
96
|
+
|
97
|
+
pHappiness = new int*[N-1];
|
98
|
+
|
99
|
+
for(int i = 0; i < N-1; ++i){
|
100
|
+
|
101
|
+
pHappiness[i] = new int[N-1];
|
102
|
+
|
103
|
+
//pHappiness[i][j] = Happiness between i and i+j+1
|
104
|
+
|
105
|
+
for(int j = 0; j+i < N-1; ++j) cin >> pHappiness[i][i+j];
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
int group[N];
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
pHappy = new long long;
|
116
|
+
|
117
|
+
pGroup = group;
|
118
|
+
|
119
|
+
ans = -2147483648;
|
120
|
+
|
121
|
+
Happiness(0);
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
cout << ans << endl;
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
最終的にこのようなコードで提出しました。
|
132
|
+
|
133
|
+
|
134
|
+
|
25
135
|
https://atcoder.jp/contests/past201912-open/submissions/13699538
|
26
136
|
|
27
|
-
↑問題のコードのリンクです。
|
137
|
+
↑問題のコードのリンクです。提出結果もこちらです。
|
28
138
|
|
29
139
|
|
30
140
|
|