fork download
  1. #pragma GCC optimize ("Ofast")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. template<class S, class T> inline S chmax(S &a, T b){
  5. if(a<b){
  6. a=b;
  7. }
  8. return a;
  9. }
  10. #define main dummy_main
  11. int main(){
  12. return 0;
  13. }
  14. #undef main
  15. int N;
  16. long long A[100000];
  17. long long s[100000];
  18. long long t[100000];
  19. class Solution{
  20. public:
  21. int maxValueAfterReverse(vector<int>& nums){
  22. int cTE1_r3A, i, mask;
  23. long long res = 0;
  24. long long tmp = 0;
  25. N = nums.size();
  26. for(i=(0);i<(N);i++){
  27. A[i] = nums[i];
  28. }
  29. if(N==1){
  30. return 0;
  31. }
  32. for(i=(1);i<(N);i++){
  33. res += abs(A[i] - A[i-1]);
  34. }
  35. for(cTE1_r3A=(0);cTE1_r3A<(2);cTE1_r3A++){
  36. for(i=(1);i<(N);i++){
  37. chmax(tmp, abs(A[0] - A[i]) - abs(A[i-1] - A[i]));
  38. }
  39. reverse(A,A+N);
  40. }
  41. for(mask=(0);mask<(1<<2);mask++){
  42. for(i=(0);i<(N-1);i++){
  43. if(mask&1){
  44. if(mask&2){
  45. s[i] = -abs(A[i]-A[i+1])+A[i]+A[i+1];
  46. }
  47. else{
  48. s[i] = -abs(A[i]-A[i+1])+A[i]-A[i+1];
  49. }
  50. }
  51. else{
  52. if(mask&2){
  53. s[i] = -abs(A[i]-A[i+1])-A[i]+A[i+1];
  54. }
  55. else{
  56. s[i] = -abs(A[i]-A[i+1])-A[i]-A[i+1];
  57. }
  58. }
  59. }
  60. for(i=(1);i<(N);i++){
  61. if(mask&1){
  62. if(mask&2){
  63. t[i] = -abs(A[i]-A[i-1])-A[i-1]-A[i];
  64. }
  65. else{
  66. t[i] = -abs(A[i]-A[i-1])-A[i-1]+A[i];
  67. }
  68. }
  69. else{
  70. if(mask&2){
  71. t[i] = -abs(A[i]-A[i-1])+A[i-1]-A[i];
  72. }
  73. else{
  74. t[i] = -abs(A[i]-A[i-1])+A[i-1]+A[i];
  75. }
  76. }
  77. }
  78. for(i=(N-1)-1;i>=(1);i--){
  79. chmax(t[i], t[i+1]);
  80. }
  81. for(i=(0);i<(N-1);i++){
  82. chmax(tmp, s[i] + t[i+1]);
  83. }
  84. }
  85. return res + tmp;
  86. }
  87. }
  88. ;
  89. // cLay varsion 20200119-1
  90.  
  91. // --- original code ---
  92. // #define main dummy_main
  93. // {}
  94. // #undef main
  95. //
  96. // int N;
  97. // ll A[1d5];
  98. // ll s[1d5], t[1d5];
  99. //
  100. // class Solution {
  101. // public:
  102. // int maxValueAfterReverse(vector<int>& nums) {
  103. // ll res = 0, tmp = 0;
  104. // N = nums.size();
  105. // rep(i,N) A[i] = nums[i];
  106. //
  107. // if(N==1) return 0;
  108. //
  109. // rep(i,1,N) res += abs(A[i] - A[i-1]);
  110. //
  111. // rep(2){
  112. // rep(i,1,N) tmp >?= abs(A[0] - A[i]) - abs(A[i-1] - A[i]);
  113. // reverse(A,A+N);
  114. // }
  115. //
  116. // rep(mask,1<<2){
  117. // rep(i,N-1) s[i] = -abs(A[i]-A[i+1]) if[mask&1, +, -] A[i] if[mask&2, +, -] A[i+1];
  118. // rep(i,1,N) t[i] = -abs(A[i]-A[i-1]) if[mask&1, -, +] A[i-1] if[mask&2, -, +] A[i];
  119. //
  120. // rrep(i,1,N-1) t[i] >?= t[i+1];
  121. // rep(i,N-1) tmp >?= s[i] + t[i+1];
  122. // }
  123. //
  124. // return res + tmp;
  125. // }
  126. // };
  127.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty