记录编号 166310 评测结果 AAAAAAAAAA
题目名称 [IOI 1994] 数塔 最终得分 100
用户昵称 Gravatar晖灰熊 是否通过 通过
代码语言 C 运行时间 0.004 s
提交时间 2015-06-14 22:12:27 内存使用 1.96 MiB
显示代码纯文本
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main () {
freopen("shuta.in", "r", stdin);
freopen("shuta.out", "w", stdout);
	int n, i, j;
	scanf("%d", &n);
	int num[n+1][n+1], ans[n+1][n+1];
	for ( i = 1; i != n+1; ++i )
		for ( j = 1; j != i+1; ++j )
			scanf("%d", &num[i][j]), ans[i][j] = num[i][j];

	for ( i = n-1; i >= 1; --i )
		for ( j = 1; j <= i; ++j )
			if ( num[i+1][j] > num[i+1][j+1] )
				num[i][j] += num[i+1][j];
			else num[i][j] += num[i+1][j+1];
	printf("%d\n", num[1][1]);
	
    int k = num[1][1], p = ans[1][1];
    printf("%d ", ans[1][1]);
    for ( i = 2; i != n+1; ++i ) {
        for ( j = 1; j != i+1; ++j ) {
            if ( k - num[i][j] == p ) {
                printf("%d ", ans[i][j]);
                k = num[i][j];
                p = ans[i][j];
                break;
            }
        }
    }
    printf("\n");
	return 0;
}