Page 1 of 1

12673 - Football

Posted: Sun Nov 10, 2013 4:58 am
by Angry Bird
Getting WA. But why? Plz help.

Code: Select all

#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>

using namespace std;

int main()
{
    int n,g,s,r,l;
    while(cin>>n>>g)
    {
        vector<int>vr,vs,vvr,vvs;
        queue<int>qr,qs;
        for(int i=0; i<n; i++)
        {
            cin>>s>>r;
            vs.push_back(s);
            vr.push_back(r);
        }
        int sum=0;
        if(vs.size()>=vr.size())
        {
            l=vs.size();
        }

        else
        {
            l=vr.size();
        }

        for(int j=0; j<l; j++)
        {
            if(vs[j]>vr[j])
            {
                vvs.push_back(vs[j]);
                vvr.push_back(vr[j]);
            }
        }

        for(int j=0; j<l; j++)
        {
            if(vs[j]==vr[j])
            {
                vvs.push_back(vs[j]);
                vvr.push_back(vr[j]);
            }
        }

        for(int j=0; j<l; j++)
        {
            if(vs[j]<vr[j])
            {
                vvs.push_back(vs[j]);
                vvr.push_back(vr[j]);
            }
        }

        int l2;
        if(vvs.size()>=vvr.size())
        {
            l2=vvs.size();
        }
        else
        {
            l2=vvr.size();
        }


        for(int i=0; i<l2; i++)
        {
            if(vvs[i]>vvr[i])
            {
                sum+=3;
            }

            else if(vvs[i]==vvr[i])
            {
                if(g==0)
                {
                    sum+=1;
                }
                else
                {
                    sum+=3;
                    g=g-1;
                }
            }

            else
            {
                if(g==0)
                {
                    sum+=0;
                }

                else if((vvr[i]-vvs[i])>g)
                {
                    sum+=0;
                }

                else if((vvr[i]-vvs[i])==g)
                {
                    sum+=1;
                    g=g-g;
                }

                else
                {
                    sum+=3;
                    g=g-(vvr[i]-vvs[i]+1);
                }
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}


Re: UVa 12673

Posted: Mon Nov 11, 2013 7:48 pm
by Kaiser
Try these case:
Input:
3 1
2 1
1 2
1 3
3 3
1 1
2 2
3 3
2 1
1 1
2 2
Output:
4
9
4

Re: UVa 12673

Posted: Mon Nov 11, 2013 8:30 pm
by Angry Bird
Me code giving output
4
9
4
But WA. Plz check it again. Or give me more input or output.

Re: UVa 12673

Posted: Mon Nov 11, 2013 11:41 pm
by abuasifkhan
But WA. Plz check it again. Or give me more input or output. @Angry Bird.
Check this case

Code: Select all

5 3
1 1
1 3
1 2
1 2
1 2
Correct output: 6
Your code is showing 4.
For some little suggestions, you have coded to much extra codes which you do not need for this program to solve. Read the problem statements thoroughly. :)

Re: UVa 12673

Posted: Tue Nov 12, 2013 6:52 pm
by fubar
I've got WA too and I pass all the cases you provided:

Edit: AC, Thanks

Re: UVa 12673

Posted: Tue Nov 12, 2013 8:25 pm
by juancate
Try this:

Code: Select all

3 10
0 8
0 2
0 8
Correct output:

Code: Select all

3

Re: UVa 12673

Posted: Wed Nov 13, 2013 10:51 pm
by brianfry713
if S > R add 3 to the answer, otherwise sort the values of R - S, then use a greedy solution.

Re: UVa 12673

Posted: Thu Nov 28, 2013 9:58 pm
by sdipu
Here is a critical IO
INPUT:

Code: Select all

7 0
4 2
1 1
1 5
2 2
3 3
4 4
0 6
OUTPUT:

Code: Select all

7

Re: 12673 - Football

Posted: Sat Sep 20, 2014 6:38 am
by alecassis
Hey Guys, can anybody please give some more test cases? My code works fine with the ones above, but i keep on getting WA :cry:

Code: Select all

removed after ACC

Re: 12673 - Football

Posted: Sat Sep 20, 2014 12:39 pm
by lighted
Input

Code: Select all

4 0
1 1
2 2
1 3
0 4
Acc Output

Code: Select all

2
Your Output

Code: Select all

4

Re: 12673 - Football

Posted: Wed Oct 01, 2014 1:30 am
by alecassis
oh! thanks, I missed a silly validation, just got AC.

Thanks a lot :D

Re: 12673 - Football

Posted: Tue Oct 21, 2014 8:38 pm
by juliannieb
Hey, can anybody help me please? My code works with all the test cases that I´ve tried, but I'm getting WA!!!

Code: Select all

#include <stdio.h>
#include <stdlib.h>

void quick_sort (int *diferencias, int inicio, int final) {
	int i, j, central;
	int pivote;
	central = (inicio + final) / 2;
	pivote = diferencias[central];

	i = inicio;
	j = final;

	do {
		while (diferencias[i] < pivote) i ++;
		while (diferencias[j] > pivote) j --;

		if (i <= j) {
			int tmp = diferencias[i];
			diferencias[i] = diferencias[j];
			diferencias[j] = tmp;
			i ++;
			j --;
		}
	} while (i <= j);

	if (inicio < j) quick_sort(diferencias, inicio, j);
	if (i < final) quick_sort(diferencias, i, final);
}

int obten_perd_emp (int *diferencias, int n) {
	int i;
	int indice = -1;
	for (i = 0; i < n; i ++) {
		if (diferencias[i] <= 0) {
			indice = i;
		}
		if (diferencias[i] > 0) break;
	}
	return indice;
}

int main () {
	int n;
	int g;
	int primero = 1;
	while (scanf("%i %i%*c", &n, &g) == 2) {
		int *diferencias;
		diferencias = (int*) malloc(n*sizeof(int));

		int i;
		int goles_anot, goles_recib;
		for (i = 0; i < n; i ++) {
			scanf("%i %i%*c", &goles_anot, &goles_recib);
			diferencias[i] = goles_anot - goles_recib;
		}

		quick_sort(diferencias, 0, n);

		int perd_emp = obten_perd_emp(diferencias, n);

		int puntos = 0;
		if (perd_emp != -1) {
			for (i = perd_emp; i >= 0; i --) {
				while (g && diferencias[i] <= 0) {
					diferencias[i] ++;
					g --;
				}
				if (diferencias[i] > 0) puntos += 3;
				else if (diferencias[i] == 0) puntos += 1;
			}

			puntos += (n - (perd_emp + 1)) * 3;
		}else {
			puntos = 3 * n;
		}
		
		if(primero) {
			printf("%i", puntos);
			primero = 0;
		}
		else printf("\n%i", puntos);
		

		free(diferencias);

	}

	return 0;
}

Re: 12673 - Football

Posted: Wed Oct 22, 2014 2:06 pm
by lighted
Your code fails some input posted above
Kaiser wrote:Try these case:
Input:
3 1
2 1
1 2
1 3
3 3
1 1
2 2
3 3
2 1
1 1
2 2
Output:
4
9
4
sdipu wrote:Here is a critical IO
INPUT:

Code: Select all

7 0
4 2
1 1
1 5
2 2
3 3
4 4
0 6
OUTPUT:

Code: Select all

7