Discuss or suggest some new features, report bugs, sign the guestbook
created
last reply
- 1
reply
- 2.3k
views
- 2
users
- 1
link
Discuss or suggest some new features, report bugs, sign the guestbook
Hello! I'm Daniel Ambort, from Santa Fe, Argentina.
I am teaching Algorithms and Data Structures in the 1st year of the UTN FRSF.
I use spoj.com since 4-5 years, but today I am having a really strange behaviour with this problem:
http://www.spoj.com/problems/CAMPA2/5
This is a bug?
Locally, the following two codes generate exactly the same output for the three test cases in the input. But the first one is accepted, and the second one gets a TLE.....
Again, locally they execute fast (under 2 seconds).
The first code is:
SPOJ submission 15375334
and the second code is:
SPOJ submission 15375309
I find out this problem when a student submited something very similar to the second code and the got a TLE. The only difference between them are the way is contructed the while to handle the input (but the behaviour is the same).
Could you take a look at this issue?
I tried with different versions of C++ and the problem is present in all of them.
Here is the first code:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
using namespace std;
int campa(int ms){
if (ms>0)
return 1 + campa(ms-15);
else return 0;}
int main() {
int hova, miva, hova2, miva2;
while(cin >> hova >> miva >> hova2 >> miva2 && (hova ||miva|| hova2 || miva2)){
int aux= campa(15 * ( ceil( miva2 % 15 / 15.0) + miva2 / 15 - ceil( miva / 15.0) ) + 60 * ( hova2 - hova ) - 14);
cout<< aux <<endl;
}
return 0;
}
Here is the seconde code:
#include
#include
#include
using namespace std;
int campa(int ms){
if (ms>0)
return 1 + campa(ms-15);
else return 0;}
int main() {
int hova, miva, hova2, miva2;
cin>>hova>>miva>>hova2>>miva2;
while (hova || miva || hova2 || miva2){
int aux= campa(15 * ( ceil( miva2 % 15 / 15.0) + miva2 / 15 - ceil( miva / 15.0) ) + 60 * ( hova2 - hova ) - 14;);
cout<< aux <<endl;
cin>>hova>>miva>>hova2>>miva2;
}
return 0;
}
Thanks for your help!
Regards.
Daniel
Topic | Category | Replies | Views | Activity |
---|---|---|---|---|
What’s wrong in my code, in the problem Euclids algorithm revisited | Online Judge System | 2 | 256 | Jun '24 |
How to Tackle Difficult Problems on SPOJ? | Online Judge System | 1 | 261 | Jun '24 |
PALIN - wrong answer | Online Judge System | 1 | 83 | Mar 23 |
Username Invalid problem | Online Judge System | 0 | 42 | Apr 14 |