Quantcast
Channel: Online Judge System - SPOJ Discussion board
Viewing all 2136 articles
Browse latest View live

Lastdig


Remove - sigxfsz

$
0
0

@mutant wrote:

Hi all. I am trying to solve the problem REMOVE. As we can see, size of output is O(n^2) and it will be pretty big. I generated output for maximum possible input and it came out to be around 37MB. My submissions are rejected with SIGXFZ error. What is the maximum file size for this problem? Is there a problem for this particular problem? I am sure my solution is correct. I am using fast I/O too.

Here is my code:

include

inline void print(int n)
{
if (n == 0)
{
putchar_unlocked('0');
putchar_unlocked('\n');
}
else if (n == -1)
{
putchar_unlocked('-');
putchar_unlocked('1');
putchar_unlocked('\n');
}
else
{
char buf[11];
buf[10] = '\n';
int i = 9;
while (n)
{
buf[i--] = n % 10 + '0';
n /= 10;
}
while (buf[i] != '\n')
putchar_unlocked(buf[++i]);
}
}

int main()
{
int size, i, j, k, l;

scanf("%d", &size);

for (i = 1; i <= size - 3; i++)
{
    for (j = i + 1; j <= size - 2; j++)
    {
    	print(i);
    	print(j);
    	print(j + 1);
    	print(j + 2);
    }
    	print(i);
    	print(j);
    	print(i + 1);
    	print(j + 1);
}

return 0;

}

Posts: 2

Participants: 1

Read full topic

TLE In MSCHED

$
0
0

@naruto09 wrote:

Problem link : http://www.spoj.com/problems/MSCHED/
my solution : http://ideone.com/BHhBgO
logic : I have sorted the array according to the amount of milk given by each cow in decreasing order.Now i pick up the cow giving the maximum amount of milk and check if there is a time slot in 0 to t-1 (t = given deadline for the cow) that can be assigned to the cow.I dont seem to get the problem in my code..

Posts: 5

Participants: 2

Read full topic

Wa mclonum | c

Wa in ALLIZWEL

$
0
0

@nonushikhar wrote:

help me plzzz getting wa!!!
note : using scanf("%c",&ch) again and again to remove '\n' and ' ' from input
tried alomost all cases
failed at judge 2
HELP !!

:::>>GOT AC

Posts: 3

Participants: 2

Read full topic

WA in AGGRCOW

$
0
0

@rishabhjain996 wrote:

#include <stdio.h>
#include <stdlib.h>
long t,k,i,j,d,size,flag,max,count;
   long a[100002],temp,sum,n;
int cmpfunc (const void * a, const void * b)
{
   return ( *(int*)a - *(int*)b );
}
int main()
{
   scanf("%ld",&t);
  	for(k=0;k<t;k++)
  	{
  		scanf("%ld %ld",&n,&d);
  		 if(n>1&&d>1)
  		{
  	  		for(i=0;i<n;i++)
  			scanf("%ld",&a[i]);
  		qsort(a, n, sizeof(long), cmpfunc);
  		max=((a[n-1]-a[0])/(d-1));
  		if(d==2)
  		{
  		printf("%ld\n",max-1);
  			continue;
		  }
  		abc:
  		count=0;
  		sum=0;
  		for(i=1;i<n-1;i++)
  		{
  			sum=sum+a[i]-a[i-1];
  			if(sum>=max)
  			{
  				sum=0;
  				count++;
			  }
  				if(count>=d-2)
  			break;
		  }
  		sum=0;
  		i++;
  		flag=0;
  		while(i<n)
  		{
  			sum=sum+a[i]-a[i-1];
  			i++;
  			flag=1;
		  }
		if(sum>=max||flag==0&&count>=d-2)
		printf("%ld\n",max);
		else
		{
			max--;
			goto abc;
		  }  
  		}  
	  }
   return(0);
}

getting wa ..
tried almost all test cases..
PLZZZ HELP!!!!!

Posts: 1

Participants: 1

Read full topic

SMPSEQ7 - Fun with Sequences (Act 5)

$
0
0

@adi_tdkr wrote:

Why I am getting Wrong Answer?? My code is correct.
int main()
{
int a[150],b,cnt1=0,cnt2=0,i,j,k,x,n,y;
scanf("%d",&n);
for(i=0;i scanf("%d",&a[i]);
}
for(k=0;k for(j=k+1;j<=k+1;j++){
if(a[k]>=a[j]){
cnt1++;
}
}
}
x=cnt1;
for(k=x;k for(j=k+1;j<=k+1;j++){
if(a[k]<=a[j]){
cnt2++;
}
}
}
y=cnt2;
if(x+y==n){
printf("Yes");
}else{
printf("No");
}
return 0;
}

Posts: 2

Participants: 2

Read full topic

Runtime error (NZEC) - Queens, Knights and Pawns?

$
0
0

@luunguyen1990 wrote:

public static void main(String[] args) {
try{
Scanner sc = new Scanner(System.in);
int m, n;
int dem2 = 0;
ArrayList ketqua = new ArrayList<>();

        n = sc.nextInt();
        m = sc.nextInt();
        while (m != 0 && n != 0) {

            boolean[][] nm = new boolean[n][m];
            for (int n3 = 0; n3 < n; ++n3)
                for (int m3 = 0; m3 < m; ++m3) {
                    nm[n3][m3] = false;
                }
            //Quân hậu
            int countq = sc.nextInt();
            int countq2 = countq;
            int[] nq = new int[countq];
            int[] mq = new int[countq];
            while (countq > 0) {
                --countq;
                nq[countq] = sc.nextInt();
                nq[countq] = nq[countq] - 1;
                mq[countq] = sc.nextInt();
                mq[countq] = mq[countq] - 1;
                nm[nq[countq]][mq[countq]] = true;
            }
            //quân mã
            int countk = sc.nextInt();
            int countk2 = countk;
            int[] nk = new int[countk];
            int[] mk = new int[countk];
            while (countk > 0) {
                --countk;
                nk[countk] = sc.nextInt();
                nk[countk] = nk[countk] - 1;
                mk[countk] = sc.nextInt();
                mk[countk] = mk[countk] - 1;
                nm[nk[countk]][mk[countk]] = true;
            }
            //quân tốt
            int countp = sc.nextInt();
            int[] np = new int[countp];
            int[] mp = new int[countp];
            while (countp > 0) {
                --countp;
                np[countp] = sc.nextInt();
                np[countp] = np[countp] - 1;
                mp[countp] = sc.nextInt();
                mp[countp] = mp[countp] - 1;
                nm[np[countp]][mp[countp]] = true;
            }
            //quân hậu
            countq = countq2;
            while (countq > 0) {
                --countq;
                for (int j = 1; ; ++j) {
                    if (nq[countq] + j < n && mq[countq] + j < m) {
                        if (!nm[nq[countq] + j][mq[countq] + j])
                            nm[nq[countq] + j][mq[countq] + j] = true;
                    } else break;
                }
                for (int j = 1; ; ++j) {
                    if (nq[countq] - j >= 0 && mq[countq] - j >= 0 && !nm[nq[countq] - j][mq[countq] - j]) {
                        nm[nq[countq] - j][mq[countq] - j] = true;
                    } else break;
                }
                for (int j = 1; ; ++j) {
                    if (nq[countq] - j >= 0 && mq[countq] + j < m && !nm[nq[countq] - j][mq[countq] + j]) {
                        nm[nq[countq] - j][mq[countq] + j] = true;
                    } else break;
                }
                for (int j = 1; ; ++j) {
                    if (nq[countq] + j < n && mq[countq] - j >= 0 && !nm[nq[countq] + j][mq[countq] - j]) {
                        nm[nq[countq] + j][mq[countq] - j] = true;
                    } else break;
                }
                for (int j = 1; ; ++j) {
                    if (nq[countq] + j < n && !nm[nq[countq] + j][mq[countq]]) {
                        nm[nq[countq] + j][mq[countq]] = true;
                    } else break;
                }
                for (int j = 1; ; ++j) {
                    if (nq[countq] - j >= 0 && !nm[nq[countq] - j][mq[countq]]) {
                        nm[nq[countq] - j][mq[countq]] = true;
                    } else break;
                }
                for (int j = 1; ; ++j) {
                    if (mq[countq] + j < m && !nm[nq[countq]][mq[countq] + j]) {
                        nm[nq[countq]][mq[countq] + j] = true;
                    } else break;
                }
                for (int j = 1; ; ++j) {
                    if (mq[countq] - j >= 0 && !nm[nq[countq]][mq[countq] - j]) {
                        nm[nq[countq]][mq[countq] - j] = true;
                    } else break;
                }
            }
            //Quân mã
            while (countk2 > 0) {
                --countk2;
                if (nk[countk] + 2 < n && mk[countk] + 1 < m)
                    nm[nk[countk] + 2][mk[countk] + 1] = true;
                if (nk[countk] + 2 < n && mk[countk] - 1 >= 0)
                    nm[nk[countk] + 2][mk[countk] - 1] = true;
                if (nk[countk] - 2 >= 0 && mk[countk] + 1 < m)
                    nm[nk[countk] - 2][mk[countk] + 1] = true;
                if (nk[countk] - 2 >= 0 && mk[countk] - 1 < m)
                    nm[nk[countk] - 2][mk[countk] - 1] = true;
                if (nk[countk] + 1 < n && mk[countk] + 2 < m)
                    nm[nk[countk] + 1][mk[countk] + 2] = true;
                if (nk[countk] + 1 < n && mk[countk] - 2 >= 0)
                    nm[nk[countk] + 1][mk[countk] - 2] = true;
                if (nk[countk] - 1 >= 0 && mk[countk] + 2 < m)
                    nm[nk[countk] - 1][mk[countk] + 2] = true;
                if (nk[countk] - 1 >= 0 && mk[countk] - 2 >= 0)
                    nm[nk[countk] - 1][mk[countk] - 2] = true;
            }
            Integer dem = 0;
            for (int n3 = 0; n3 < n; ++n3)
                for (int m3 = 0; m3 < m; ++m3) {
                    if (!nm[n3][m3]) {
                        ++dem;
                    }

                }
            ketqua.add( dem);
            dem2++;
            n = sc.nextInt();
            m = sc.nextInt();
        }
        for (int j3 = 0; j3 < dem2; ++j3)
            System.out.println("Board " + (j3 + 1) + " has " + ketqua.get(j3) + " safe squares.");
    }catch (NumberFormatException e){
    }
}

Posts: 1

Participants: 1

Read full topic


Requesting help regarding NZEC error for the next palindrome(PALIN) problem

Time limit exceeded CRDS - Cards

$
0
0

@adi_tdkr wrote:

#include <stdio.h>

int main(void) {
	 int t;
    scanf("%d",&t);
    while(t--){
long long int n,sum=0,cnt=0;
int i,j;
scanf("%d",&n);
for(i=n;i>=1;i--){
    cnt=cnt+i*2;
    sum=sum+(i-1);
}
printf("%d",sum+cnt);
   printf("\n");
   }

	return 0;
}

Posts: 1

Participants: 1

Read full topic

WA on FERT21_1

$
0
0

@wi_lius wrote:

I tried this input on my program (don't mind that the characters repeats):

7
C*(A+B)
(A+B+D*E)*C
C*B*A
D+A+F+((((G+C)*R*D)))
V
(A+A)*(B+B)*(C+C)*(D+D)*(E+E)*(F+F)*(G+G)*(H+H)*(I+I)*(J+J)*(K+K)*(L+L)*(M+M)*(N+N)
A*(B+C)*(D+E+F)*(G+H+I+J)*(K+L+M+N+O)*(P+Q+R+S+T+U)*(V+W+X+Y+Z)

It produces:

A*C+B*C
C*D*E+A*C+B*C
A*B*C
C*D*R+D*G*R+A+D+F
V
A*B*C*D*E*F*G*H*I*J*K*L*M*N+A*B*C*D*E*F*G*H*I*J*K*L*M*N+...
A*B*D*G*K*P*V+A*B*D*G*K*P*W+A*B*D*G*K*P*X+...

However, I get WA. I even tried to change the variables to numbers (A=1, B=2, ...) in the two long expressions and calculate the result and the input value matches output value. What am I missing?

Posts: 1

Participants: 1

Read full topic

NSTEPS - Number Steps

$
0
0

@adi_tdkr wrote:

What's wrong with my code I am getting wrong answer?
int main()
{
int t;
scanf("%d",&t);
while(t--){
int x,y,i,j,k;
scanf("%d%d",&x,&y);
if(x%2==0){
if(x==y){
printf("%d\n",x+y);
}
if(y>x){
printf("No Number\n");
}
if(y<x){
y==x-2?printf("%d",x+y):printf("No Number");
}
}else if(x==1 && y==1){
printf("%d",1);
}else{
if(x==y && x!=1 && y!=1){
printf("%d\n",x+y-1);
}
if(y>x){
printf("No Number\n");
}
if(y<x){
y==x-2?printf("%d",x+y-1):printf("No Number");
}}
}
return 0;
}

Posts: 2

Participants: 2

Read full topic

hs08test - atm

$
0
0

@adi_tdkr wrote:

Why I am getting Wrong answer??
int main()
{
int i,x,j,k;
float y;
scanf("%d",&x);
scanf("%f",&y);
if(x<y){
printf("%.2f",y-x-0.50);
}else{
printf("%d",x);
}
return 0;
}

Posts: 2

Participants: 2

Read full topic

gss1 wa

$
0
0

@nonushikhar wrote:

GETTING Wa IN GSS1
TRIED ALMOST ALL CASES ON FORUM AND NET....GIVES CORRECT ANSWER FOR THEM
done using segment tree....maintained four fields in node of tree, 'i' argument in every fns indicates inedex of element in seg_tree to be filled.....
PLZ HELP !!!!!
(plz give the test case where i m failing)

#include <stdio.h>
using namespace std ;
struct node {
	long int l_sum,max_sum,sum,r_sum ;
}seg_tree[9999999];
long int arr[100000],n,m ;
void create_seg_tree(long int,long int,long int) ;
long int maxxx(long int ,long int) ;
node get_sum(long int,long int,long int,long int,long int) ;
node merge (node a,node b) ;
int main () {
	long int i ,j ,a,b;
	scanf("%ld",&n) ;
	for (i=0;i<n;i++)
	  scanf("%ld",&arr[i]) ;
	create_seg_tree(0,0,n-1) ;   
    scanf("%ld",&m) ;
    for (i=0;i<m;i++) 
	{  scanf("%ld%ld",&a,&b) ;
	   printf("%ld\n",get_sum(a-1,b-1,0,n-1,0).max_sum) ;
	}
	return  0 ;
}
long int maxxx(long int a,long int b) {
	if (a>b)
	  return  a ;
	else
	  return  b ;  
}
node merge(node a,node b) {
	node aux ;
    aux.sum=a.sum + b.sum ;
	if (a.l_sum==-999999999&&a.r_sum==-999999999&&a.max_sum==-999999999&&a.sum==-999999999)
        return b ;
	if (b.l_sum==-999999999&&b.r_sum==-999999999&&b.max_sum==-999999999&&b.sum==-999999999)
	    return a ;
	aux.max_sum=maxxx(maxxx(a.max_sum , b.max_sum ) , a.r_sum + b.l_sum) ;
    if (b.l_sum-a.sum+a.l_sum>=0)
      aux.l_sum=b.l_sum+a.sum ;
    else
	  aux.l_sum=a.l_sum ;  
	if (a.r_sum-b.sum+b.r_sum>=0)
	  aux.r_sum=a.r_sum+b.sum ;
	else
	  aux.r_sum=b.r_sum ;  
	return aux ;  
}
node get_sum (long int a,long int b,long int l,long int u,long int i) {
	int m =(u+l)/2 ;
	node aux ;
	aux.l_sum=aux.max_sum=aux.r_sum=aux.sum=-999999999 ;
	if (a<=l&&b>=u)
	  return seg_tree[i] ;
	else if (b<l||a>u)
	  return  aux ;
	else
	  return merge(get_sum(a,b,l,m,2*i+1),get_sum(a,b,m+1,u,2*i+2)) ; 
}
void create_seg_tree (long int i,long int l,long int u) {
	long int m1=(u+l)/2 ;
	long int m2=m1+1 ;
	if (l==u)
	{  seg_tree[i].l_sum=seg_tree[i].r_sum=seg_tree[i].max_sum=seg_tree[i].sum=arr[l] ;
	}
 	else
    {  create_seg_tree(2*i+1,l,m1) ;
	   create_seg_tree(2*i+2,m2,u) ;
	   seg_tree[i].sum=seg_tree[2*i+1].sum + seg_tree[2*i+2].sum ;
	   seg_tree[i].max_sum=maxxx(maxxx(seg_tree[2*i+1].max_sum , seg_tree[2*i+2].max_sum ) , seg_tree[2*i+1].r_sum + seg_tree[2*i+2].l_sum) ;
	   if (seg_tree[2*i+2].l_sum-seg_tree[2*i+1].sum+seg_tree[2*i+1].l_sum>=0)
	      seg_tree[i].l_sum=seg_tree[2*i+2].l_sum+seg_tree[2*i+1].sum ;
	   else
	      seg_tree[i].l_sum=seg_tree[2*i+1].l_sum ;
	   if (seg_tree[2*i+1].r_sum-seg_tree[2*i+2].sum+seg_tree[2*i+2].r_sum>=0)
	      seg_tree[i].r_sum=seg_tree[2*i+1].r_sum+seg_tree[2*i+2].sum ;   
       else
	      seg_tree[i].r_sum=seg_tree[2*i+2].r_sum ;
	}
}

Posts: 1

Participants: 1

Read full topic

WA in CATM

$
0
0

@colton_moler wrote:

I'm trying to solve the CATM problem (http://www.spoj.com/problems/CATM/)
From what I can tell the only way the cats can catch the mouse is if the mouse is in a diagonal between the two cats to start with

removed for AC

so in my code i check to see if the mouse is between the two different possible diagonals between the two cats. However when try the code in the judge i get WA even though it works with the test cases provided when i try it on my computer

Posts: 1

Participants: 1

Read full topic


LASTDIG2 - The last digit re-visited

$
0
0

@adi_tdkr wrote:

int main(void) {
	int t;
long long int a , b ,last;
scanf("%d",&t);
 
while(t--){
     scanf("%lld%lld",&a,&b);
        if(b==0) printf("1\n");
        else
     {
        last = b % 4 ;
        if (last ==0)  last = 4 ;
        a = (long long int) pow(a,last);
        printf("%lld\n",a%10);
     }
}

Posts: 6

Participants: 3

Read full topic

CANTON - Count on Cantor

Apparently wrong solution getting accepted for SPOJ-FARIDA (Basic DP)

$
0
0

@tonyalmonds wrote:

0
down vote
favorite
http://www.spoj.com/problems/FARIDA/

include

long long int max(long long int a, long long int b)
{
if(a > b)
return a;
else
return b;
}

int main()
{
int t, j;

scanf("%d", &t);

for(j = 0; j < t; j++)
{
    int n, i;
    long long int a[1001], d[1001];

    scanf("%d", &n);

    for(i = 0; i < n; i++)
        scanf("%lld", &a[i]);

    d[0] = a[0];
    d[1] = max(d[0], a[1]);

    for(i = 2; i < n; i++)
        d[i] = max(d[i-1], a[i] + d[i-2]);

    printf("Case %d: %lld\n", j+1, d[n-1]);
}

return 0;

}
Consider the test case:

1
7
3 2 3 4 44 2 1 90
The answer has got to be: 3+3+44+90 = 140 but the output is 3+3+44+1 = 51 which's wrong. yet the solution is accepted as correct! How?

Posts: 2

Participants: 2

Read full topic

TEST - Life, the Universe, and Everything: Python

$
0
0

@superman1984 wrote:

Hi frineds!
Can you help me, pleace:

I have RUNTIME ERROR

Python 3.5 (I choose Python 3 (Python 3.4))

list = []
while (True):
x = input()
if not x:
break
list.append(x)

for x in list:
if x == "42":
break
else: print(x)

Posts: 6

Participants: 4

Read full topic

WA in GERGOVIA

$
0
0

@colton_moler wrote:

in trying to solve the wine trading in gergovia problem http://www.spoj.com/problems/GERGOVIA/. I have a solution that works for the provided test cases however i continually get WA.

removed for AC (apparently i wasn't using scanf correctly)

This should be taking a greedy approach to add the work based on the previous remaining wine that needs to be traded. I've run through it on paper and it should work. What am i doing wrong?

Posts: 1

Participants: 1

Read full topic

Viewing all 2136 articles
Browse latest View live