Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main(){
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- long long sum=0;
- int n,x,p,t;
- stack<int> dfs;
- cin>>x;
- if(x&1) n=3; else n=2;
- for(int i=0;i<n;i++) dfs.emplace(x);
- while(!dfs.empty()){
- p=dfs.top();
- dfs.pop();
- cin>>x;
- if(x){
- t=p-x;
- sum+=t>0? t:-t;
- if(x&1) n=3; else n=2;
- for(int i=0;i<n;i++) dfs.emplace(x);
- }
- }
- cout<<sum;
- return 0;
- }
- /*
- Zero Judge j124. 3. 石窟探險
- https://zerojudge.tw/ShowProblem?problemid=j124
- 2024 June 16
- AC (31ms, 356KB)
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement