Advertisement
AlbertMourato

Untitled

Dec 20th, 2015
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <bits/stdc++.h>
  3. //%lld
  4. typedef long long ll;
  5. using namespace std;
  6. ll vetor[1000000], aux;
  7. int visitado[1000000];
  8. int main(){
  9.     freopen("in.txt", "r", stdin);
  10.     //freopen("out.txt", "w", stdout);
  11.     int n, t = 0, cnt = 1;
  12.     cin>>n;
  13.     aux = 0;
  14.     for(int i = 0;i<n;i++){
  15.         cin>>vetor[i];
  16.         aux+=vetor[i];
  17.     }
  18.     bool vai = true;
  19.     while(vai){
  20.         if(vetor[t]%2==0){//esquerda
  21.             if(vetor[t]>=1)aux-=1;
  22.             if(vetor[t]>=1)vetor[t]--;
  23.             if(t==0){
  24.                 vai = false;
  25.             }else{
  26.                 if(!visitado[t])cnt++;
  27.                 visitado[t] = 1;
  28.                 t--;
  29.             }
  30.         }else{//direita
  31.             if(vetor[t]>=1)aux-=1;
  32.             if(vetor[t]>=1)vetor[t]--;
  33.             if(t==n-1){
  34.                 vai = false;
  35.             }else{
  36.                 if(!visitado[t])cnt++;
  37.                 visitado[t] = 1;
  38.                 t++;
  39.             }
  40.         }
  41.     }
  42.     cout<<cnt<<" "<<aux<<endl;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement