Advertisement
076

Zero Judge j124. 3. 石窟探險

076
Jun 16th, 2024
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4.     ios_base::sync_with_stdio(false);
  5.     cin.tie(0);
  6.     long long sum=0;
  7.     int n,x,p,t;
  8.     stack<int> dfs;
  9.     cin>>x;
  10.     if(x&1) n=3; else n=2;
  11.     for(int i=0;i<n;i++) dfs.emplace(x);
  12.     while(!dfs.empty()){
  13.         p=dfs.top();
  14.         dfs.pop();
  15.         cin>>x;
  16.         if(x){
  17.             t=p-x;
  18.             sum+=t>0? t:-t;
  19.             if(x&1) n=3; else n=2;
  20.             for(int i=0;i<n;i++) dfs.emplace(x);
  21.         }
  22.     }
  23.     cout<<sum;
  24.     return 0;
  25. }
  26. /*
  27. Zero Judge j124. 3. 石窟探險
  28. https://zerojudge.tw/ShowProblem?problemid=j124
  29. 2024 June 16
  30. AC (31ms, 356KB)
  31. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement