如果N为3,并且三棵树都掉落了苹果,则E为3。即[0, 1, 2]、[1, 2, 0]、[2, 1, 0]不被算作同一组。
#include <iostream>
#include <vector>
using namespace std
;
int main() {
int N
;
cin
>> N
;
vector
<bool> dropped(N
);
int total
= 0;
for (int i
= 0; i
< N
; ++i
) {
int M
;
cin
>> M
;
int num
;
cin
>> num
;
for (int j
= 1; j
< M
; ++j
) {
int x
;
cin
>> x
;
if (x
> 0) {
if (num
> x
) dropped
[i
] = true;
num
= x
;
} else {
num
+= x
;
}
}
total
+= num
;
}
int D
= 0;
for (int i
= 0; i
< N
; ++i
) if (dropped
[i
]) ++D
;
int E
= 0;
for (int i
= 0; i
+ 2 < N
; ++i
) if (dropped
[i
] && dropped
[i
+ 1] && dropped
[i
+ 2]) ++E
;
if (dropped
[N
-2] && dropped
[N
-1] && dropped
[0]) ++E
;
if (dropped
[N
-1] && dropped
[0] && dropped
[1]) ++E
;
cout
<< total
<< " " << D
<< " " << E
<< endl
;
return 0;
}