fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. signed main(){
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr);
  9.  
  10. int n;
  11. cin >> n;
  12.  
  13. int t = 0; // vị trí kim
  14. int dem = 0; // số lần chạm 0 (KHÔNG tính ban đầu)
  15.  
  16. while(n--){
  17. char x;
  18. int y;
  19. cin >> x >> y;
  20.  
  21. if(x == 'L'){
  22. if(y >= t)
  23. dem += (y - t) / 100 + 1;
  24. t = ((t - y) % 100 + 100) % 100;
  25. }
  26. else{ // 'R'
  27. int i0 = (100 - t) % 100;
  28. if(i0 == 0) i0 = 100;
  29. if(y >= i0)
  30. dem += (y - i0) / 100 + 1;
  31. t = (t + y) % 100;
  32. }
  33. }
  34.  
  35. cout << dem;
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 5320KB
stdin
5
L 5
R 10
L 5
R 120
L 40
stdout
5