codejam qualification round question 3

Revision en3, by zereff, 2021-04-10 09:43:02

Following is the code I submitted for question 3 after contest. for all the vectors created by my code I tested them with the first question code. It passed on all the combinations but codejam gave WA. I would be very thankful if someone can point out the mistake. ~~~~

include<bits/stdc++.h>

using namespace std;

define ll long long int

define MOD 1000000007

define N 100000 //array size

int main(){ int testcases,it=1; cin>>testcases; while(it<=testcases){

int n,c;
    cin>>n>>c;
    vector<ll> vec(n,0);
    cout<<"Case #"<<it<<":"; it++;
    if(c < n-1 || c> (n*(n+1)/2-1)){
        cout<<" IMPOSSIBLE\n";}
    else{
        ll val = 1,curr=0,d=-99,sig=-1;
        c= c-n+1;
        int j;
        for(j=1;j<n;j++){
            val = 1+max(0,min(n-j,c));
            c= c-(n-j);
            if(d==1 && val ==1){

                while(curr >= 0 && curr <n  && vec[curr]!=0) curr+=sig;
                if(curr<0 || vec[curr]!=0 ){
                    if(sig==-1) sig =1;
                    else sig =-1;
                    while(vec[curr]!=0) curr+=sig;
                }
                vec[curr]=j;
            }
            else if(j%2==0){
                vec[curr-val-1]=j;
                curr-=val;
                sig=-1;
            }else{
                vec[curr+val-1]=j;
                curr+=val;  
                sig =1;
            }
            d=val;
        }
        for(ll i=0;i<n;i++){
            if(vec[i]==0){
                vec[i]=n;
            }
            cout<<" "<<vec[i];
        }
        vec.clear();
        cout<<endl;

    }
}

}~~

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en8 English zereff 2021-04-10 09:50:47 4 Tiny change: '006d12d7\n```\ninc' -> '006d12d7\n\n\n```\ninc'
en7 English zereff 2021-04-10 09:50:12 104
en6 English zereff 2021-04-10 09:45:29 8
en5 English zereff 2021-04-10 09:44:28 4
en4 English zereff 2021-04-10 09:43:36 10
en3 English zereff 2021-04-10 09:43:02 43
en2 English zereff 2021-04-10 09:41:59 38
en1 English zereff 2021-04-10 09:41:13 1937 Initial revision (published)