Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define cin(v) for (auto &i : v) cin >> i;
- #define cout(v) for (auto &i : v) cout << i << " "; cout<<'\n';
- #define ll long long
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define MOD 1000000007
- #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs"<< "\n";
- void Warding()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- /*
- STOP USING int
- */
- ll dmg;
- ll rec(ll target,ll pos, ll curr_idx, ll sec, vector<pair<int, pair<int,int>>> &v){
- ll hit = 0;
- if(pos == target) return 0;
- if(sec > 10) return target - pos;
- if(curr_idx < v.size() && v[curr_idx].first == sec){
- while(curr_idx < v.size() && v[curr_idx].first == sec){
- hit += (pos >= v[curr_idx].second.first && pos <= v[curr_idx].second.second);
- curr_idx++;
- }
- }
- hit *= dmg;
- ll step_back = 1 + hit + rec(target, pos - 1, curr_idx, sec + 1, v);
- ll step_front = 1 + hit + rec(target, pos + 1, curr_idx, sec + 1, v);
- ll same_pos = 1 + hit + rec(target, pos, curr_idx, sec + 1, v);
- return min({step_back, step_front, same_pos});
- }
- void solve(){
- ll n, x, target; cin>>n>>x>>target>>dmg;
- vector<pair<int, pair<int,int>>> v(n);
- for(int i=0; i<n; i++){
- cin>>v[i].second.first>>v[i].second.second>>v[i].first;
- }
- sort(all(v));
- // for(auto&i:v) cout<<i.second.first<<" "<<i.second.second<<" "<<i.first<<endl;
- cout<<rec(target, x, 0ll,0ll, v)<<endl;
- }
- int main()
- {
- Warding();
- int TC = 1;
- // cin >> TC;
- while (TC--)
- {
- solve();
- }
- Time
- }
Advertisement
Add Comment
Please, Sign In to add comment