Thread: input files using command line arguments possible?

  1. #16
    Registered User
    Join Date
    Dec 2018
    Posts
    38
    You don't seem to be interested. That's okay.
    Last edited by bruteforce; 12-15-2018 at 08:22 PM.

  2. #17
    Registered User
    Join Date
    Oct 2018
    Posts
    42
    Hey bruteforce sorry for the delay, no I'm interested But it's night here when it's day somewhere else so it's hard to be in step I apologize.
    I'm thrilled to see your fast solution. Also about PMing, you're right, I just clicked on your name in red on the left hand side bar and then clicked "send a private message" but when I submitted a test message, nothing was sent. So anyways... here's my email: [email protected]
    Also about the input file, I've uploaded it on my Dropbox, and here's the link to it: Dropbox - input11.txt (just hit the download button).
    Thanks for your time.

  3. #18
    Registered User
    Join Date
    Dec 2018
    Posts
    38
    I got your PMs (just now as I was busy yesterday). But when I click on your name I am not given the option to send a PM, although I am able to respond to your PM so I did so. It might be the case that you need a certain number of posts before you can initiate a PM so that a person can't make an account and start spamming people with PMs (I guess). I expect the option to appear shortly!

    You had just posted your GDB commands list so I thought you were around, but that was just an assumption on my part. I had posted the code in that last post but then deleted/replaced it after about 55 minutes since I think you can't edit a post after an hour here and I didn't want to leave the code on display for too long.

    I actually joined that hackerearth site and tried running the code. Embarassingly, although it was correct, it doesn't seem much faster. I'll send it to you anyway, though, since it may be interesting as an alternative approach.

    Here's the embarassing timing results from the site:
    old: 1.27568
    new: 1.27477

    I get somewhat different results when I run them over again. I wonder if one of the secrets of a low time is to run it at a time of low site usage (when India is asleep?). For instance, I just tried the "best" C solution that was given a time of 1.2292 and I got 1.26078. I then ran my new one again right after that and got 1.25213! So I "beat" the top submission ... kind of.

    As for input11.txt, I'm not sure where you get that from. After submitting the code I'm given the option to download the test files. input11.txt is not the file that you've posted. Maybe different people are given different files? But that doesn't seem fair! I'm even more confused now. My input11.txt is a file with 100000 values where the first is one-million the other 99999 are ten-million.

    Anyway, with your input11.txt I get 419872311 when running it with both the "old" program and the new one.
    Last edited by bruteforce; 12-17-2018 at 12:08 PM.

  4. #19
    Registered User
    Join Date
    Oct 2018
    Posts
    42
    I read your message.
    All in all, the messaging system here is REALLLLY strange because at the time I sent you that message, it just vanished! and now that you have replied it's there! And now I replied your recent message too and it's again vanished! But from the previous experience I can conclude that it's in your inbox now (fingers crossed)
    Thanks a lot.

  5. #20
    Registered User
    Join Date
    Dec 2018
    Posts
    38
    Guess who has the best time for a C program for this problem?

    input files using command line arguments possible?-brute2-png

    I thought I'd finish off the thread with the final code and some timing info from the hackerearth site. These times are all for exactly the same code. The time of day is Eastern Standard Time (GMT-5). So, assuming India is a heavy site user, these times are between about 8pm to 5am there.

    input files using command line arguments possible?-times01-png

    The difference between the best and worst times is over 0.125 seconds. So if you're ever that close to the top time, you should definitely run it a few more times. I got the best time of 1.21617 about 15 seconds after I got a time of 1.28226. Pretty much makes the "best time" meaningless!

    Code:
    #include <stdio.h>
     
    long long v[100001];
     
    int main() {
        int n;
        scanf("%d", &n);
     
        for (int i = 0; i < n; i++)
            scanf("%lld", &v[i]);
        v[n] = 0;
     
        int end_offset = 1, max_end_offset = 2;
        long long maxsum = v[n - 1];
     
        for (int i = n - 1; i-- > 0; ) {
            v[i] += v[i + 1];
     
            long long newsum = v[i] - v[n - end_offset];
            if (newsum > maxsum)
                maxsum = newsum;
     
            if (++end_offset == max_end_offset) {
                end_offset = 0;
                ++max_end_offset;
            }
        }
     
        printf("%lld\n", maxsum);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. command line arguments
    By KBriggs in forum C Programming
    Replies: 7
    Last Post: 06-25-2009, 01:57 PM
  2. Handling multiple input files from command line
    By cnfwriter in forum C Programming
    Replies: 13
    Last Post: 08-25-2008, 08:07 AM
  3. command line arguments
    By St0rM-MaN in forum C Programming
    Replies: 10
    Last Post: 05-07-2007, 04:40 AM
  4. Command line arguments
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 05-02-2002, 11:59 AM
  5. command line arguments
    By zbap in forum C++ Programming
    Replies: 1
    Last Post: 03-13-2002, 11:29 AM

Tags for this Thread