AL-Yassin-105's blog

By AL-Yassin-105, history, 12 months ago, In English

at the last "Div 2" round i sent solution for problem B but i get Wrong answer on test 2 ....I spend a lot of time try to discover why my idea is wrong?!! actually my idea and my code was true , but because (sqrt function do not work in GNU 20 with long long number and same function work with GNU 17 i get wrong answer and my rate will decrase more than 150 point,** so please if you know some issues like this, please type it in the comment to know it , especially in differences between these two compilers**

my code AC on GNU 17 , WA on GNU 20

https://codeforces.com/contest/1809/submission/198835668

https://codeforces.com/contest/1809/submission/198811956

  • Vote: I like it
  • +11
  • Vote: I do not like it

»
12 months ago, # |
  Vote: I like it +8 Vote: I do not like it

Auto comment: topic has been updated by AL-Yassin-105 (previous revision, new revision, compare).

»
12 months ago, # |
  Vote: I like it +8 Vote: I do not like it

You could've evaded it using sqrtl as 198837320 or implementing sqrt using binary search.

However, this issue is old. There is a separate blog I wrote abt before.

  • »
    »
    12 months ago, # ^ |
    Rev. 2   Vote: I like it +8 Vote: I do not like it

    thanks , and i want to know if there are more differences , there was another issue in another problem in that time i do not know what the difference between them

»
12 months ago, # |
  Vote: I like it +9 Vote: I do not like it

Never mind bro, you can rise again next contest , just never give up :)

»
12 months ago, # |
  Vote: I like it +4 Vote: I do not like it

You can't write a struct name as data and pass it as a parameter of a function. It will run in C++14 but give errors in C++17 and C++20.

Here is an example code:

#include <iostream>
using namespace std;

struct data{
    int a,b;
};

int sum(data f){
    return f.a+f.b;
}
int main()
{
    struct data x;
    x.a=1;
    x.b=2;
    cout<<sum(x)<<endl;
    return 0;
}

It will run in C++14. But give errors in C++17 and C++20.

I faced this problem in the ICPC2022 preliminary round to solve the problem of Proximity Card Data Statistics. I used the struct name as data and pass it into a function, as a result, I was getting a Compilation error in the contest. But my code was smoothly running on my local pc. As a result, I lose 45 minutes of figuring out the problem.

  • »
    »
    12 months ago, # ^ |
    Rev. 2   Vote: I like it +10 Vote: I do not like it

    do you mean data is a key word ?! in c++17 and c++20 !?

    • »
      »
      »
      12 months ago, # ^ |
      Rev. 2   Vote: I like it +5 Vote: I do not like it

      No, data isn't a keyword. You can use it as a variable. i.e

      #include <iostream>
      using namespace std;
      
      
      int main()
      {
          int data =5;
          cout<<data<<endl;
          return 0;
      }
      

      You can run it in C++14, C++17, C++20, etc. But when you use data as a struct name and pass it to a function as the parameter (I mention it in a previous comment) then it won't work in C++17 and C++20 (As I tested it in C++14, C++17, and C++20).

      And it is happening because, In C++14, it is allowed to omit the struct/union/class keyword when referring to a member of a struct/union/class, as long as the intended member is not a type name. This is called "implicit conversion from class to its first data member" and is a language feature. However, in C++17 and C++20, this feature was removed due to inconsistency in the language and potential conflicting interpretations by different compilers. As a result, using a struct name as data and passing it as a parameter of a function is no longer allowed in these newer versions of C++.

  • »
    »
    12 months ago, # ^ |
    Rev. 2   Vote: I like it +2 Vote: I do not like it

    You can't use data because it is declared in C++ std namespace. However, if you change function sum to

    int sum(::data f){
        return f.a+f.b;
    }
    

    It will be compiled without any problems

    • »
      »
      »
      12 months ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      Yes, It will be compiled without any problems. Thank you for bringing up this idea.

»
12 months ago, # |
  Vote: I like it -7 Vote: I do not like it

it's your mistake not anyone else you should know every thing about the function you use in your code