Uva problem122

Revision en2, by rks_mak, 2017-03-13 13:36:12

I came across this question on UVa and it seemed really easy but it didn't take much time to realise that I was wrong. I have implemented it and tried on all possible testcases but it still gives wrong. The only problem my code seems to have is that it doesn't knows when to stop asking for more inputs. Can someone please help me. I would really appreciate your effort or suggestion. The hash sign has been intentionally left out as it zooms the succeding word, thereby decreasing the readability.

include <bits/stdc++.h> using namespace std;

define rep(i, a, n) for(int i = a; i < n; ++i) //define per(i, a, n) for(int i = n — 1; i >= a; --i) define pb push_back define mp make_pair define all(x) (x).begin(),(x).end() define fi first define se second define sz(x) ((int)(x).size())

typedef vector vi; typedef long long ll; typedef pair<int, int> pii;

const int mod = 1e9 + 7; const double pi = 3.14159265358979;

int a[260];

bool check(int i){ bool temp = true; while(i){ if(a[i] == -1){temp = false;} i /= 2; } return temp; }

int main(){
//#ifndef ONLINE_JUDGE //assert(freopen("1.in", "r", stdin)); //assert(freopen("1.out", "w", stdout)); //#endif

#ifdef ONLINE_JUDGE
    assert(ios_base::sync_with_stdio(false));
#endif


while(cin.peek() != EOF){
rep(i, 0, 260){a[i] = -1;}

string s;
bool flag = true;
int node_count = 0;

while(cin >> s){
    if(s == "()"){
       break;       
    }
    else{                        
       string path = "", str_val = "";
       rep(i, 0, s.length()){
         if(s[i] == 'R' or s[i] == 'L'){path += s[i];}
         if(s[i] == '0' or s[i] == '1' or s[i] == '2' or s[i] == '3' or s[i] == '4' or s[i] == '5' or s[i] == '6' or s[i] == '7' or s[i] == '8' or s[i] == '9'){str_val += s[i];}
       }
       stringstream ss;
       ss << str_val;
       int val;
       ss >> val;
       int pos = 1;
       rep(i, 0, path.length()){
         if(path[i] == 'L'){pos *= 2;}
         else{pos += (pos + 1);}
       }
       //cout << val << "#" << str_val << "#" << pos << "#" << a[pos] << "#" << path <<endl;
       if(a[pos] != -1){flag = false;}
       else{a[pos] = val;}
       node_count++;
    }
}
rep(i, 1, 260)
{
    if(a[i] != -1)
    {
       flag = check(i);
    }
}
if(flag){
    rep(i, 1, 260){if(a[i] != -1)cout << a[i] << " ";}
    }
    else{cout << "not complete";}

    cout << "\n";


    //#ifndef ONLINE_JUDGE
//  printf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    //#endif
    }
return 0;

}

Tags bit/fenwick tree, spoj ctrick

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English rks_mak 2017-07-11 17:10:00 2534
en2 English rks_mak 2017-03-13 13:36:12 386 Tiny change: 'stion.\n\n#include <' -> 'stion.\n\n #include <'
en1 English rks_mak 2017-03-13 13:28:41 2901 Initial revision (published)