Блог пользователя dikki99

Автор dikki99, история, 4 года назад, По-английски

include

include<math.h>

include

using namespace std;

bool check(int* arr,int n,int k){ int sum=0; int curr=0; for(int i=0;i<k;i++) sum+=arr[i]; curr=sum; for(int i=k;i<n;i++){ curr+=arr[i]-arr[i-k]; if(curr!=sum) return false; } return true; }

int main(){ int t; cin>>t; while(t--){ int n,k; cin>>n>>k; int arr[n]; map<int,int> m; for(int i=0;i<n;i++){ cin>>arr[i]; m[arr[i]]++; } if(n==k){ cout<<k<<endl; for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<endl; } else if(m.size()>k||m.size()==n){ cout<<-1<<endl; } else if(check(arr, n, k)){ cout<<n<<endl; for(int i=0;i<n;i++){ cout<<arr[i]<<" "; } cout<<endl; } else{ cout<<n*m.size()<<endl; for(int i=0;i<n;i++){ for(map<int, int>::iterator itr=m.begin();itr!=m.end();itr++){ cout<first<<" "; } }

cout<<endl;
}

}// t; return 0; }

This is my code for DIV.2 b question and this giving wrong answer on 4th pretest but it is giving correct output on my local ide.

  • Проголосовать: нравится
  • -40
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +24 Проголосовать: не нравится

Oh god. Please format your code using the block-code option.

I can't understand it, much less read it.

»
4 года назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

Did you check for undefined behavior by compiling with -fsanitize=undefined? Or run with custom invocation to see what the different output. Generally you are responsible for making sure your code runs the same on all computers; I've spent much time debugging differences between the contest environment and my computer on codeforces and on different sites.

Everybody's solution runs on the same judging computers so I'm pretty sure it is "fair". Try being a little bit more respectful to the people who work hard to put these contests on.

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Note that you can always run your program on Codeforces to see if you get the correct input-output.

»
4 года назад, # |
  Проголосовать: нравится +20 Проголосовать: не нравится

Hi. Here are some tips which might make your code working:

Add this in as many places as possible: {int a, b, c; a = 0; b = 0; c = a + b;}

Compilers work better for people who love coding, let cf compiler know your feelings! Example:

{int a, b, c;// I love coding
a = 0;// assignment is love
b = 0;// assignment is life
c = a + b;}// addition is awesome

Btw, you don't use 3d treaps. I think you should add those to get AC.

Lmk if it helps

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I think adding "machine learning" also helps you get AC.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    the thing is that the output codeforces is showing for my code is simply wrong as it is not possible i'm multiplying map size which is 5 with the n size which is 9 and it is showing 72 instead of 45. please help.

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится +6 Проголосовать: не нравится

      Wow! Concerning. It's either overflow or CF c++ not working. I suggest using 128 bit integers. If that doesn't help. You should try adding pragmas. And if it's still not working, I'm afraid we'll have to contact codeforces staff.