fork download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <stack>
  12. #include <list>
  13. #include <cmath>
  14. #include <iomanip>
  15. #define dibs reserve
  16. #define OVER9000 1234567890
  17. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  18. #define tisic 47
  19. #define soclose 1e-8
  20. #define chocolate win
  21. // so much chocolate
  22. #define patkan 9
  23. #define ff first
  24. #define ss second
  25. #define abs(x) ((x < 0)?-(x):x)
  26. #define uint unsigned int
  27. #define dbl long double
  28. using namespace std;
  29. // mylittledoge
  30.  
  31. struct info {
  32. double d;
  33. int c[2];
  34.  
  35. bool operator<(const info &I) const {
  36. return d < I.d;}
  37. };
  38.  
  39. int main() {
  40. cin.sync_with_stdio(0);
  41. cin.tie(0);
  42. int N;
  43. cin >> N;
  44. vector<info> A(N*(N-1)/2);
  45. int x =0;
  46. for(int i =0; i < N; i++) for(int j =0; j < N; j++) {
  47. double d;
  48. cin >> d;
  49. if(j > i) A[x++].d =d;}
  50. x =0;
  51. for(int i =0; i < N; i++) for(int j =0; j < N; j++) {
  52. int c;
  53. cin >> c;
  54. if(j > i) A[x++].c[1] =c;}
  55. x =0;
  56. for(int i =0; i < N; i++) for(int j =0; j < N; j++) {
  57. int c;
  58. cin >> c;
  59. if(j > i) A[x++].c[0] =c;}
  60. sort(A.begin(),A.end());
  61. N =A.size();
  62.  
  63. cout << N/2 << " ";
  64. vector< vector<int> > C[2];
  65. for(int i =0; i < 2; i++) C[i].resize(N+1,vector<int>(N+tisic,OVER9000));
  66. C[0][0][0] =0;
  67. for(int i =0; i < N; i++) for(int j =0; j <= N; j++) {
  68. for(int k =0; k < 2; k++) {
  69. if(j > 0) C[k][i+1][j-1] =min(C[k][i+1][j-1],C[k][i][j]+A[i].c[1]);
  70. C[k][i+1][j+1] =min(C[k][i+1][j+1],C[k][i][j]+A[i].c[0]);}
  71. C[1][i+1][j] =min(C[1][i+1][j],C[0][i][j]);}
  72.  
  73. cout << C[N%2][N][0] << "\n";
  74. return 0;}
  75.  
  76. // look at my code
  77. // my code is amazing
  78.  
Runtime error #stdin #stdout #stderr 0s 3440KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc