ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1003. Parity

I've got WA on 1003. Somebody give me some good test...
Posted by earthman 16 Jun 2002 17:44
MY CODE:
#include <iostream.h>

#define maxN 5005
int i,Len,N;
int mn[maxN];
int L[maxN];
int R[maxN];
int pL[maxN];
int pR[maxN];

void search(int l,int r,int &il,int &ir,int &pl,int &pr){
    int j;
    il = ir = -1;
    for(j = 0;j < i;j++){
        if(r + 1 == L[j]){
            ir = j;
            pr = pL[j];
            break;
        }
    }
    for(j = 0;j < i;j++){
        if(l == R[j] + 1){
            il = j;
            pl = pR[j];
            break;
        }
    }
    for(j = 0;j < i;j++){
        if(r == R[j]){
            ir = j;
            pr = pR[j];
            break;
        }
    }
    for(j = 0;j < i;j++){
        if(l == L[j]){
            il = j;
            pl = pL[j];
            break;
        }
    }
}

int findroot(int k){
    if(mn[k] == -1)return -1;
    if(mn[k] == k)return k;
    int l = findroot(mn[k]);
    mn[k] = l;
    return l;
}

int add(int a,int b,int c){
    int pl,pr,il,ir;
    L[i] = a;
    R[i] = b;
    search(a,b,il,ir,pl,pr);
    if(il == -1 && ir == -1){
        pL[i] = 0;
        pR[i] = c;
        mn[i] = i;
    }
    if(il != -1 && ir == -1){
        int rl = findroot(il);
        mn[i] = rl;
        pL[i] = pl;
        pR[i] = (pL[i] + c) % 2;
    }
    if(il == -1 && ir != -1){
        int rr = findroot(ir);
        mn[i] = rr;
        pR[i] = pr;
        pL[i] = (pR[i] - c + 2) % 2;
    }
    if(il != -1 && ir != -1){
        int rl = findroot(il);
        int rr = findroot(ir);
        mn[i] = rl;
        if(rl == rr){
            if(((pl + c) % 2) != (pr % 2)){
                return 0;
            }
        }else{
            pL[i] = pl;
            pR[i] = (pL[i] + c) % 2;
            if(pr != pR[i])
                for(int k = 0;k < i;k++)
                    if(findroot(k) == rr)pR[k] =
(pR[k] + 1) % 2,pL[k] = (pL[k] + 1) % 2;
            int o = findroot(ir);
            mn[o] = i;
        }
    }
    return 1;
}

void main(void){
    for(;;){
        cin >> Len;
        if(Len == -1)break;
        cin >> N;
        int bad = 0;
        for(i = 0;i < N;i++){
            mn[i] = -1;
            int a,b;char k[10];
            cin >> a >> b >> k;
// FOR debug reasons only...
//            if(a == -1){cout << "Wrong input";return;}
//            if(b == -1){cout << "Wrong input";return;}
            if(!add(a,b,(k[0] == 'e') ? 0 : 1)){
                cout << i << "\n";
                bad = 1;
                for(i++;i < N;i++)
                    cin >> a >> b >>  k;
                break;
            }
        }
        if(!bad)cout << N << "\n";
    }
}
http://www.fi.muni.cz/ceoi/problems.html
Posted by Andrey Popyk (popyk@ief.tup.km.ua) 17 Jun 2002 18:15
Re: http://www.fi.muni.cz/ceoi/problems.html
Posted by earthman 17 Jun 2002 23:26
i know that this task from CEOI 99 but i don't want to see sol. and
theier test, because in that case it is a cheat :-)
Re: http://www.fi.muni.cz/ceoi/problems.html
Posted by Andrey Popyk (popyk@ief.tup.km.ua) 18 Jun 2002 17:23
But you can find your mistake!

And if I send you this test, is it cheat? :-)

> i know that this task from CEOI 99 but i don't want to see sol. and
> theier test, because in that case it is a cheat :-)