fork download
  1. #pragma GCC optimize ("Ofast")
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. template<class S, class T> inline S min_L(S a,T b){
  5. return a<=b?a:b;
  6. }
  7. #define main dummy_main
  8. int main(){
  9. return 0;
  10. }
  11. #undef main
  12. int N;
  13. int lf[3][50000];
  14. int rg[3][50000];
  15. class Solution{
  16. public:
  17. vector<int> shortestDistanceColor(vector<int>& colors, vector<vector<int>>& q){
  18. int i;
  19. int j;
  20. int k;
  21. int t;
  22. vector<int> res;
  23. N = colors.size();
  24. for(i=0;i<(N);i++){
  25. for(k=0;k<(3);k++){
  26. if(i==0){
  27. lf[k][i] = -1073709056;
  28. }
  29. else{
  30. lf[k][i] = lf[k][i-1];
  31. }
  32. if(colors[i]==k+1){
  33. lf[k][i] = i;
  34. }
  35. }
  36. }
  37. for(i=N-1;i>=0;i--){
  38. for(k=0;k<(3);k++){
  39. if(i==N-1){
  40. rg[k][i] = 1073709056;
  41. }
  42. else{
  43. rg[k][i] = rg[k][i+1];
  44. }
  45. if(colors[i]==k+1){
  46. rg[k][i] = i;
  47. }
  48. }
  49. }
  50. for(k=0;k<(q.size());k++){
  51. i = q[k][0];
  52. j = q[k][1] - 1;
  53. t =min_L(i-lf[j][i], rg[j][i]-i);
  54. if(t > N){
  55. t = -1;
  56. }
  57. res.push_back(t);
  58. }
  59. return res;
  60. }
  61. }
  62. ;
  63. // cLay varsion 20190914-1
  64.  
  65. // --- original code ---
  66. // #define main dummy_main
  67. // {}
  68. // #undef main
  69. //
  70. // int N;
  71. // int lf[3][50000], rg[3][50000];
  72. //
  73. // class Solution {
  74. // public:
  75. // vector<int> shortestDistanceColor(vector<int>& colors, vector<vector<int>>& q) {
  76. // int i, j, k, t;
  77. // vector<int> res;
  78. //
  79. // N = colors.size();
  80. // rep(i,N){
  81. // rep(k,3){
  82. // if(i==0) lf[k][i] = -int_inf;
  83. // else lf[k][i] = lf[k][i-1];
  84. // if(colors[i]==k+1) lf[k][i] = i;
  85. // }
  86. // }
  87. // for(i=N-1;i>=0;i--){
  88. // rep(k,3){
  89. // if(i==N-1) rg[k][i] = int_inf;
  90. // else rg[k][i] = rg[k][i+1];
  91. // if(colors[i]==k+1) rg[k][i] = i;
  92. // }
  93. // }
  94. //
  95. // rep(k,q.size()){
  96. // i = q[k][0];
  97. // j = q[k][1] - 1;
  98. // t = min(i-lf[j][i], rg[j][i]-i);
  99. // if(t > N) t = -1;
  100. // res.push_back(t);
  101. // }
  102. //
  103. // return res;
  104. // }
  105. // };
  106.  
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