fork(1) download
  1. void getAns(const vector<char> &arr, vector<vector<int>> &queries){
  2. int n = arr.size();
  3. int removeD = 0;
  4. int joinF = 0;
  5. int start = INT_MAX, end = INT_MIN;
  6.  
  7. //Get start-end positions of 'F'
  8. for(int i = 0; i < n; i++){
  9. if(arr[i] =='F'){
  10. start = min(start, i);
  11. end = max(end, i);
  12. }
  13. }
  14.  
  15. //Get 'D' between start-end of 'F'
  16. for(int i = start: i < end; i++){
  17. if(arr[i] == 'D')
  18. removeD++;
  19. }
  20.  
  21. //Get minimum adjacent swpas required to remove non'F' out of 'F' bounded subarray
  22. for(int i = start; i < end; i++){
  23. if(arr[i] != 'F'){
  24.  
  25. //Get nearest leftExit distance
  26. int leftExit = i - start;
  27.  
  28. //Get nearest rightExit distance
  29. int rightExit = end - i;
  30.  
  31. //Move this non'F' space in the minimum direction till it get's out
  32. joinF += min(leftExit, rightExit);
  33.  
  34. //update start-end on basis of direction in which non'F' went to get out
  35. if(leftExit <= rightExit)
  36. start++;
  37. else end--;
  38. }
  39. }
  40.  
  41.  
  42. //Now we have removeD -> no. of operations to remove dirty
  43. //joinF - no. of operations to join all F after cleaning all inbetween dirty cells, if any
  44.  
  45. for(auto query: queries){ // query -> {x,y} {move food, clean dirty}
  46. long long moveFoodCost = query[0];
  47. long long cleanDirtyCost = query[1];
  48. long long totalCost = ( removeD * cleanDirtyCost ) + ( joinF * moveFoodCost );
  49.  
  50. cout << totalCost <<endl
  51. }
  52. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:19: error: ‘vector’ does not name a type
 void getAns(const vector<char> &arr, vector<vector<int>> &queries){
                   ^~~~~~
prog.cpp:1:25: error: expected ‘,’ or ‘...’ before ‘<’ token
 void getAns(const vector<char> &arr, vector<vector<int>> &queries){
                         ^
prog.cpp: In function ‘void getAns(int)’:
prog.cpp:2:10: error: ‘arr’ was not declared in this scope
  int n = arr.size();
          ^~~
prog.cpp:5:14: error: ‘INT_MAX’ was not declared in this scope
  int start = INT_MAX, end = INT_MIN;
              ^~~~~~~
prog.cpp:5:14: note: ‘INT_MAX’ is defined in header ‘<climits>’; did you forget to ‘#include <climits>’?
prog.cpp:1:1:
+#include <climits>
 void getAns(const vector<char> &arr, vector<vector<int>> &queries){
prog.cpp:5:14:
  int start = INT_MAX, end = INT_MIN;
              ^~~~~~~
prog.cpp:10:12: error: ‘min’ was not declared in this scope
    start = min(start, i);
            ^~~
prog.cpp:11:4: error: ‘end’ was not declared in this scope
    end = max(end, i);
    ^~~
prog.cpp:11:10: error: ‘max’ was not declared in this scope
    end = max(end, i);
          ^~~
prog.cpp:16:12: error: initializer in range-based ‘for’ loop
  for(int i = start: i < end; i++){
            ^
prog.cpp:16:25: error: ‘end’ was not declared in this scope
  for(int i = start: i < end; i++){
                         ^~~
prog.cpp:16:28: error: expected ‘)’ before ‘;’ token
  for(int i = start: i < end; i++){
     ~                      ^
                            )
prog.cpp:16:30: error: ‘i’ was not declared in this scope
  for(int i = start: i < end; i++){
                              ^
prog.cpp:22:25: error: ‘end’ was not declared in this scope
  for(int i = start; i < end; i++){
                         ^~~
prog.cpp:32:13: error: ‘min’ was not declared in this scope
    joinF += min(leftExit, rightExit);
             ^~~
prog.cpp:45:18: error: ‘queries’ was not declared in this scope
  for(auto query: queries){   // query -> {x,y} {move food, clean dirty}
                  ^~~~~~~
prog.cpp:45:18: note: suggested alternative: ‘query’
  for(auto query: queries){   // query -> {x,y} {move food, clean dirty}
                  ^~~~~~~
                  query
prog.cpp:50:3: error: ‘cout’ was not declared in this scope
   cout << totalCost <<endl
   ^~~~
prog.cpp:50:23: error: ‘endl’ was not declared in this scope
   cout << totalCost <<endl
                       ^~~~
prog.cpp:50:23: note: suggested alternative: ‘enum’
   cout << totalCost <<endl
                       ^~~~
                       enum
stdout
Standard output is empty