12673 - Football

All about problems in Volume 126. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
Angry Bird
New poster
Posts: 21
Joined: Mon Apr 08, 2013 8:38 am

12673 - Football

Post by Angry Bird » Sun Nov 10, 2013 4:58 am

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;
}


Kaiser
New poster
Posts: 2
Joined: Tue Sep 03, 2013 8:56 pm

Re: UVa 12673

Post by Kaiser » Mon Nov 11, 2013 7:48 pm

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

Angry Bird
New poster
Posts: 21
Joined: Mon Apr 08, 2013 8:38 am

Re: UVa 12673

Post by Angry Bird » Mon Nov 11, 2013 8:30 pm

Me code giving output
4
9
4
But WA. Plz check it again. Or give me more input or output.

abuasifkhan
New poster
Posts: 1
Joined: Mon Nov 11, 2013 8:57 pm

Re: UVa 12673

Post by abuasifkhan » Mon Nov 11, 2013 11:41 pm

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. :)

fubar
New poster
Posts: 2
Joined: Sat Mar 30, 2013 8:39 am

Re: UVa 12673

Post by fubar » Tue Nov 12, 2013 6:52 pm

I've got WA too and I pass all the cases you provided:

Edit: AC, Thanks
Last edited by fubar on Mon Jul 28, 2014 8:28 am, edited 1 time in total.

juancate
New poster
Posts: 3
Joined: Thu Mar 28, 2013 2:09 am

Re: UVa 12673

Post by juancate » Tue Nov 12, 2013 8:25 pm

Try this:

Code: Select all

3 10
0 8
0 2
0 8
Correct output:

Code: Select all

3

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: UVa 12673

Post by brianfry713 » Wed Nov 13, 2013 10:51 pm

if S > R add 3 to the answer, otherwise sort the values of R - S, then use a greedy solution.
Check input and AC output for thousands of problems on uDebug!

sdipu
New poster
Posts: 23
Joined: Sun May 19, 2013 1:50 am

Re: UVa 12673

Post by sdipu » Thu Nov 28, 2013 9:58 pm

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
Check out UVA Arena - a software build for UVA solvers @ http://dipu-bd.github.io/UVA-Arena/

alecassis
New poster
Posts: 10
Joined: Sat Sep 20, 2014 6:36 am

Re: 12673 - Football

Post by alecassis » Sat Sep 20, 2014 6:38 am

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
Last edited by alecassis on Tue Dec 02, 2014 7:09 am, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 12673 - Football

Post by lighted » Sat Sep 20, 2014 12:39 pm

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
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

alecassis
New poster
Posts: 10
Joined: Sat Sep 20, 2014 6:36 am

Re: 12673 - Football

Post by alecassis » Wed Oct 01, 2014 1:30 am

oh! thanks, I missed a silly validation, just got AC.

Thanks a lot :D

juliannieb
New poster
Posts: 1
Joined: Tue Oct 21, 2014 8:26 pm

Re: 12673 - Football

Post by juliannieb » Tue Oct 21, 2014 8:38 pm

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;
}

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 12673 - Football

Post by lighted » Wed Oct 22, 2014 2:06 pm

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
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Post Reply

Return to “Volume 126 (12600-12699)”