jeudi 4 avril 2019

Not the same output when build by visual studio and idenone.com

I do this problems. When i run by visual-studio-17, the output is 2474 (correct output), but when i run by ideone.com the output not the same when i change my MAX (2482,2492,..), and i summited to hackerrank and i got wrong-answer in this test-case Problems is: https://www.hackerrank.com/challenges/beautiful-triplets

Input: https://hr-testcases-us-east-1.s3.amazonaws.com/20732/input02.txt?AWSAccessKeyId=AKIAJ4WZFDFQTZRGO3QA&Expires=1554374777&Signature=WVWUm7%2FX%2Bnih7cj7GBfpnOaMDp8%3D&response-content-type=text%2Fplain

Output: https://hr-testcases-us-east-1.s3.amazonaws.com/20732/output02.txt?AWSAccessKeyId=AKIAJ4WZFDFQTZRGO3QA&Expires=1554375487&Signature=HQS%2Fty2jXLomcsaAgPHwI61ZLk8%3D&response-content-type=text%2Fplain Here is my code:

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#define MAX 30000
using namespace std;
long long d[MAX],dd[MAX];
int main()
{
    freopen("beautifultriplets.inp", "r", stdin);
    freopen("beautifultriplets.out", "w", stdout);
    long long n, k,x;
    for(long long i = 0; i < MAX; i++)
        dd[i] = 1;
    vector<int>a;
    cin >> n >> k;
    for (long long i = 0; i < n; i++)
    {
        cin >> x;
        a.push_back(x);
        d[x]++;
    }
    for (long long i = 1; i < n; i++)
    {
        if (d[a[i] - k] > 0)
        {
            dd[a[i]]=dd[a[i] - k]+1;
        }
    }
    long long ans = 0;
    for (long long i = 0; i < n; i++)
    {
        //cout << dd[a[i]] << " ";
        if (dd[a[i]] >= 3)
            ans += d[a[i]] * d[a[i] - k] * d[a[i] - k - k];
    }
    cout << ans;
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire