记录编号 243829 评测结果 AAAAAAAAAA
题目名称 [IOI 1994] 数塔 最终得分 100
用户昵称 GravatarAntiLeaf 是否通过 通过
代码语言 C++ 运行时间 0.061 s
提交时间 2016-03-30 18:03:04 内存使用 0.00 MiB
显示代码纯文本
  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. using namespace std;
  5. namespace mine{
  6. int c,x,a[110],i,j;
  7. bool neg;
  8. inline int getint(){
  9. x=neg=0;
  10. do c=getchar();while(c==' '||c=='\n'||c=='\r'||c=='\t');
  11. if(c=='-'){
  12. neg=true;
  13. c=getchar();
  14. }
  15. for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c^48);
  16. if(neg)return -x;
  17. return x;
  18. }
  19. inline int fgeti(FILE* fin){
  20. x=neg=0;
  21. do c=fgetc(fin);while(c==' '||c=='\n'||c=='\r'||c=='\t');
  22. if(c=='-'){
  23. neg=true;
  24. c=fgetc(fin);
  25. }
  26. for(;c>='0'&&c<='9';c=fgetc(fin))x=(x<<1)+(x<<3)+(c^48);
  27. if(neg)return -x;
  28. return x;
  29. }
  30. inline void putint(int x){
  31. neg=x<0;
  32. if(neg)x=-x;
  33. i=0;
  34. do{
  35. a[i++]=x%10+48;
  36. x/=10;
  37. }while(x);
  38. if(neg)putchar('-');
  39. for(j=i-1;j>=0;j--)putchar(a[j]);
  40. }
  41. inline void fputi(FILE* fout,int x){
  42. neg=x<0;
  43. if(neg)x=-x;
  44. i=0;
  45. do{
  46. a[i++]=x%10+48;
  47. x/=10;
  48. }while(x);
  49. if(neg)putchar('-');
  50. for(j=i-1;j>=0;j--)fputc(a[j],fout);
  51. }
  52. inline void fputi(int x,FILE* fout){
  53. neg=x<0;
  54. if(neg)x=-x;
  55. i=0;
  56. do{
  57. a[i++]=x%10+48;
  58. x/=10;
  59. }while(x);
  60. if(neg)putchar('-');
  61. for(j=i-1;j>=0;j--)fputc(a[j],fout);
  62. }
  63. inline void put(const char* s){
  64. x=strlen(s);
  65. for(i=0;i<x;i++)putchar(s[i]);
  66. }
  67. inline void fput(FILE* fout,const char* s){
  68. x=strlen(s);
  69. for(i=0;i<x;i++)fputc(s[i],fout);
  70. }
  71. inline void fput(const char* s,FILE* fout){
  72. x=strlen(s);
  73. for(i=0;i<x;i++)fputc(s[i],fout);
  74. }
  75. inline void puts(const char* s){
  76. x=strlen(s);
  77. for(i=0;i<x;i++)putchar(s[i]);
  78. putchar('\n');
  79. }
  80. inline void fputs(FILE* fout,const char* s){
  81. x=strlen(s);
  82. for(i=0;i<x;i++)fputc(s[i],fout);
  83. fputc('\n',fout);
  84. }
  85. inline void fputs(const char* s,FILE* fout){
  86. x=strlen(s);
  87. for(i=0;i<x;i++)fputc(s[i],fout);
  88. fputc('\n',fout);
  89. }
  90. }
  91. int MAIN();
  92. int haha=MAIN();
  93. int n,a[90][90],f[90][90];
  94. bool left[90][90];
  95. int dfs(int,int);
  96. int main(){;}
  97. inline int MAIN(){
  98. #define COGS
  99. #ifdef COGS
  100. freopen("shuta.in","r",stdin);
  101. freopen("shuta.out","w",stdout);
  102. #endif
  103. memset(f,-1,sizeof(f));
  104. n=mine::getint();
  105. for(int i=1;i<=n;i++)for(int j=1;j<=i;j++){
  106. a[i][j]=mine::getint();
  107. if(i==n)f[i][j]=a[i][j];
  108. }
  109. mine::putint(dfs(1,1));
  110. putchar('\n');
  111. for(int i=1,j=1;i<=n;i++){
  112. mine::putint(a[i][j]);
  113. putchar(' ');
  114. if(!left[i][j])j++;
  115. }
  116. return putchar('\n');
  117. }
  118. int dfs(int x,int y){
  119. if(f[x][y]==-1){
  120. if(dfs(x+1,y)<dfs(x+1,y+1)){
  121. left[x][y]=false;
  122. return f[x][y]=f[x+1][y+1]+a[x][y];
  123. }
  124. else{
  125. left[x][y]=true;
  126. return f[x][y]=f[x+1][y]+a[x][y];
  127. }
  128. }
  129. return f[x][y];
  130. }