fork download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. using namespace std;
  5. int n, p[1503], tp[1503], ans = 2147483647;
  6. char v[1503][5];
  7. int main() {
  8. n = 1000;
  9. for(int i=1; i<=n; i++) {
  10. p[i]=127*i;
  11. v[i][1] = 'A'; v[i][2] = 'B'; v[i][3] = rand()%6?'C':0;
  12. }
  13. int x;
  14. for(int i=1; i<=n; i++) {
  15. x = 0;
  16. if(v[i][1] == 'A' || v[i][2] == 'A' || v[i][3] == 'A') {
  17. x += p[i];
  18. int tmp1 = p[i];
  19. p[i] = 0;
  20. for(int j=1; j<=n; j++) {
  21. if(v[j][1] == 'B' || v[j][2] == 'B' || v[j][3] == 'B') {
  22. x += p[j];
  23. int tmp2 = p[j];
  24. p[j] = 0;
  25. for(int k=1; k<=n; k++) {
  26. if(v[k][1] == 'C' || v[k][2] == 'C' || v[k][3] == 'C') {
  27. x += p[k];
  28. ans = min(ans, x);
  29. x -= p[k];
  30. }
  31. }
  32. p[j] = tmp2;
  33. x -= p[j];
  34. }
  35. }
  36. p[i] = tmp1;
  37. x -= p[i];
  38. }
  39. }
  40. printf("%d", ans == 2147483647 ? -1 : ans);
  41. }
Success #stdin #stdout 1.96s 15248KB
stdin
Standard input is empty
stdout
127