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 1638. Bookworm

how to simplify solution
Posted by arrammis 26 Jul 2014 16:50
I got accepted but it works slow (0.031),
I want to get solution in one formula
how to do that ?
here's my current solution

#include <iostream>

int main(int argc, char * argv[])
{
    int n1, n2, n3, n4;
    std::cin >> n1 >> n2 >> n3 >> n4;

    if ( n3 < n4 )
    {
        std::cout << n1 * (n4 - n3 - 1) + 2 * n2 * (n4 - n3);
    }
    else
    {
        std::cout << n1 * (n3 - n4 + 1) + 2 * n2 * (n3 - n4);
    }

    return 0;
}

thanks

Edited by author 26.07.2014 16:51

Edited by author 26.07.2014 16:52

Edited by author 26.07.2014 16:53
Re: how to simplify solution
Posted by Sandu Petrasco 19 Aug 2016 19:47
#include <bits/stdc++.h>

using namespace std;
int a, b, c, d;
int main()
{
  cin >> a >> b >> c >> d;
  cout << ((a + 2 * b) * (d - c - 1) + 2 * b) * (c < d ? 1 : -1);
  return 0;
}