|
|
back to boardhow to simplify solution 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 #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; } |
|
|