fork download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <string>
  9. #include <queue>
  10. #include <stack>
  11. #include <algorithm>
  12. #include <iomanip>
  13. #define dibs reserve
  14. #define OVER9000 1234567890
  15. #define patkan 9
  16. #define tisic 47
  17. #define soclose 10e-7
  18. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  19. #define chocolate win
  20. #define ff first
  21. #define ss second
  22. #define abs(x) ((x < 0)?-(x):(x))
  23. // mylittlepony
  24. using namespace std;
  25.  
  26. int main() {
  27. //freopen("dice.in","r",stdin);
  28. int T;
  29. scanf(" %d",&T);
  30.  
  31. for(int t =0; t < T; t++) {
  32. int N;
  33. cin >> N;
  34. vector<int> V(N);
  35. vector<bool> is(5001,false);
  36. for(int i =0; i < N; i++) scanf(" %d",&V[i]);
  37. vector<int> A(6,0); A[0] =1;
  38. vector<int> B(6,0); B[0] =V[0]-1;
  39. int S =0;
  40. for(int i =N-1; i >= 0; i--) {
  41. V[i] -=V[0];
  42. S +=V[i];
  43. is[V[i]] =true;}
  44.  
  45. bool ok =false;
  46. int op =0;
  47. for(int a =2+(int)(N == 36); a < min(12,N-8); a++) if(!ok)
  48. for(int b =a+1; b < N-7; b++) if(!ok && !(N == 36 && b < 5))
  49. for(int c =b+1; c < N-6; c++) if(!ok && !(N == 36 && c < 8))
  50. for(int d =c+1; d < N-5; d++) if(!ok)
  51. for(int e =d+1; e < N-4; e++) if(!ok)
  52. for(int f =e+1; f < N-3; f++) if(!ok) {
  53. vector<int> x(6,0), y(6,0);
  54. x[1] =V[1];
  55. y[1] =V[a]-x[1];
  56. x[2] =V[b]-y[1]; if(y[1] > V[2] && x[2] > V[2]) continue;
  57. y[2] =V[c]-x[2];
  58. x[3] =V[d]-y[2];
  59. y[3] =V[e]-x[3];
  60. x[4] =V[f]-y[3];
  61. int Sx =x[1]+x[2]+x[3]+x[4];
  62. int Sy =y[1]+y[2]+y[3];
  63. if(N == 36) y[4] =(S/6-Sx-Sy-V[N-1]);
  64. bool ok1 =true;
  65. for(int i =0; i < 5; i++) for(int j =0; j < 4+(int)(N == 36); j++)
  66. if(x[i] < 0 || y[j] < 0 || !is[x[i]+y[j]]) {
  67. ok1 =false;
  68. break;}
  69. if(!ok1) continue;
  70.  
  71. for(int g =f+1; g < ((N == 36)?(f+2):(N-2)); g++) if(!ok)
  72. for(int h =max(N-7,g+1); h < N-1; h++) {
  73. if(N != 36) y[4] =V[g]-x[4]; if(y[4] < 0 || !is[y[4]]) continue;
  74. x[5] =V[h]-y[4]; if(x[5] < 0 || !is[x[5]]) continue;
  75. y[5] =V[N-1]-x[5]; if(y[5] < 0 || !is[y[5]]) continue;
  76.  
  77. set<int> S;
  78. for(int i =0; i < 6; i++) for(int j =0; j < 6; j++)
  79. S.insert(x[i]+y[j]);
  80. if(S == set<int>(V.begin(),V.end())) {
  81. for(int i =0; i < 6; i++) A[i] =A[0]+x[i];
  82. for(int i =0; i < 6; i++) B[i] =B[0]+y[i];
  83. ok =true;}
  84. if(ok) break;}}
  85.  
  86. printf("Case %d:\n",t+1);
  87. for(int i =0; i < 6; i++) {
  88. if(i > 0) printf(" ");
  89. printf("%d",A[i]);}
  90. printf("\n");
  91. for(int i =0; i < 6; i++) {
  92. if(i > 0) printf(" ");
  93. printf("%d",B[i]);}
  94. printf("\n");}
  95. return 0;}
  96.  
  97. // look at my code
  98. // my code is amazing
Success #stdin #stdout 0.54s 3436KB
stdin
1
11
2 3 4 5 6 7 8 9 10 11 12
stdout
Case 1:
1 35 159 435 535 783
299 417 428 513 574 716
Case 2:
1 3 5 7 9 11
13 20 32 44 47 61
Case 3:
1 2 3 4 5 6
1 2 3 4 5 6
Case 4:
1 2 5 6 36 41
12 14 20 22 28 30
Case 5:
1 11 245 392 782 906
151 501 669 711 809 863
Case 6:
1 3 26 494 598 722
297 434 542 616 997 1042
Case 7:
1 5 6 7 10 11
25 33 41 49 56 63
Case 8:
1 2 3 16 17 18
6 9 18 27 36 39