把int改long long后,得分增加了20:
【代码】
#include <stdio.h>
#include <stdlib.h>
typedef struct _CHILD
{
int height;
long long unhappiness;
long long increment;
} CHILD;
int main(void)
{
int n, i, j;
long long count;
CHILD *children;
CHILD child;
scanf("%d", &n);
children = (CHILD *)malloc(n * sizeof(CHILD));
for (i = 0; i < n; i++)
{
scanf("%d", &children[i].height);
children[i].unhappiness = 0;
children[i].increment = 1;
}
for (i = 0; i < n - 1; i++)
{
for (j = 0; j < n - 1 - i; j++)
{
if (children[j].height > children[j + 1].height)
{
children[j].unhappiness += children[j].increment;
children[j].increment++;
children[j + 1].unhappiness += children[j + 1].increment;
children[j + 1].increment++;
child = children[j];
children[j] = children[j + 1];
children[j + 1] = child;
}
}
}
count = 0;
for (i = 0; i < n; i++)
{
count += children[i].unhappiness;
}
printf("%I64d\n", count);
free(children);
return 0;
}