Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8043229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:50:15+00:00 2026-06-05T04:50:15+00:00

i was trying to do this problem but i could not able to get

  • 0

i was trying to do this problem but i could not able to get it accepted , its input is large so i thought to take it with strings but still i am getting wrong answer .
problem statement is here BISHOPS

here is my code:

#include<iostream>
#include<string.h>
#include<cstdio>
#include<vector>

using namespace std;

int main()
{
    string s;
    int z;
    cin>>s;
    z = s.length();
    int i;
    vector<int>v;
    int arr[z];
    for(i=0;i<z;i++)
    {
        arr[i] = (s[i]-'0');
    }

    if ((arr[0] == 0 || arr[0] ==  1) && z == 1)
    {
        printf("%d",arr[0]);
    }
    else
    { 
        int carry = 0;
        for(i=z-1;i>=0;i--)
        {
            int x = (carry + 2*arr[i])%10;
            v.push_back(x);
            carry = ( 2*arr[i] )/10;
        }
        if(carry > 0)
        {
            v.push_back(carry);
        }

        int t = v.size();
        int g=0;
        if(v[g] >=2)
        {
            v[g] = v[g]-2;
        }
        else
        {
            v[g] = 8;
            g++;
            while(v[g] == 0)
            {
                v[g] = 9;
                g++;
            }
            v[g] = v[g] -1;
        } 


        if(v[t-1] == 0)
        {
            for(i=t-2;i>=0;i--)
                {
                    printf("%d",v[i]);
                }
        }
        else
        {
            for(i=t-1;i>=0;i--)
            {
                printf("%d",v[i]);
            }
        }
    }

        return 0;
}

question is to find max non attackable bishops in the problem for nxn chess board ,i think i am doing right because except for 1×1 for every oyher chess board max non attacakable bishops will be 2*n-2.but still spoj is giving wrong answer

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:50:17+00:00Added an answer on June 5, 2026 at 4:50 am

    You have integer overflow for all inputs larger than INT_MAX:

    int y=0,i,z;
    z = s.length();
    for(i=0;i<z;i++)
    {
        y = y*10 + (s[i]-'0');
    }
    

    You are trying to convert the input to an int, which typically is a signed 32-bit type with INT_MAX equal to 2147483647 = 231-1. Whenever the input is larger than that, at the tenth digit you have overflow (which, by the way, is undefined behaviour).

    You need a way to represent/handle numbers larger than that, up to 10100. No standard integer type in C or C++ is wide enough to handle that. You have to roll your own big-integer type (since SPOJ presumably doesn’t link the code with GMP). For this problem, something very simple works well enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to solve this problem, its not a homework question, its just code
I have been trying to solve this problem for a while, but couldn't with
ive being trying to cope with this problem but still. I need your help.
i'm trying to find a way to match this problem but i'm LOST i
I've been trying to solve this problem for a number of days now but
I've been trying to debug this problem for many hours, but to no avail.
I have been trying to get this to work with several tutorials/answers here, but
Trying to solve this problem . I would like to learn how the bootstrapper
I am trying to solve this problem. I have a series of SELECT statements
I'm trying to solve this problem : http://uva.onlinejudge.org/external/7/732.html . For the given example, they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.