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

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

Thank you for participating!

1971A - My First Sorting Problem

Idea: flamestorm

Tutorial
Solution

1971B - Different String

Idea: flamestorm

Tutorial
Solution

1971C - Clock and Strings

Idea: flamestorm

Tutorial
Solution

1971D - Binary Cut

Idea: flamestorm

Tutorial
Solution

1971E - Find the Car

Idea: mesanu

Tutorial
Solution

1971F - Circle Perimeter

Idea: mesanu

Tutorial
Solution

1971G - XOUR

Idea: mesanu

Tutorial
Solution

1971H - ±1

Idea: flamestorm

Tutorial
Solution
Разбор задач Codeforces Round 944 (Div. 4)
  • Проголосовать: нравится
  • +64
  • Проголосовать: не нравится

»
2 года назад, скрыть # |
 
Проголосовать: нравится +36 Проголосовать: не нравится

🌹

»
2 года назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится
»
2 года назад, скрыть # |
 
Проголосовать: нравится +25 Проголосовать: не нравится
»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Dude, you included the wrong tutorial for problem B.

»
2 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

problem b editorial for now is an editorial of an old div4b problem, fix pls

upd1: fixed now

»
2 года назад, скрыть # |
← Rev. 5  
Проголосовать: нравится 0 Проголосовать: не нравится

https://codeforces.me/contest/1971/submission/260448426

-> this is giving out of bound

https://codeforces.me/contest/1971/submission/260447515

-> this is not giving out of bond

Both code are same,, just the writing style is different..

Why is this happening?? Thanks in advance..

flamestorm(could you plz help sir)

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

took 30 min to solve F+G, still have no idea how I got WA from E 260451462

too bad actually

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

please tell me why this is not getting accepted but (PROBLEM E) long long ans = brr[it] + ((drr[i]-arr[it]) / ((arr[it+1]-arr[it])/(brr[it+1]-brr[it])));

this is accepted? how? long long ans = brr[it] + (drr[i]-arr[it]) * (brr[it+1]-brr[it])/(arr[it+1]-arr[it]);

260452416 260452100

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
»
2 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone explain me please(with reference to problem E) — as the answer needs to be rounded off to nearest integer value...so let say total comes out to be like 1.6 then the rounded off answer wouldn't be 2 instead of 1. And without using round() 1 will be the ans, then how it's correct without using round function? Am i misunderstood the word rounded *down(instead off) which means to always round off to floor value? But i sumbitted with using round() also..and why ac for that?

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

I wrote this code for problem F During the contest.. But now I really have no idea way it works !!!!!!

void calculate() {
    int r;
    cin >> r;
    int ans = 2;
    for(int x = -1*r; x <= r; x++) {
        ans += ((int)sqrt((r+1)*(r+1)-x*x-1)-(int)sqrt(r*r-x*x-1))*2;
    }   
    cout << ans << endl;
}

There is a case when r*r-x*x-1 becomes negative and then sqrt(negative) !!

I didn't notice that during the contest but I am really surprised to see it works!

the second thing is why the answer is 2 ? when I wrote this weird solution I noticed that it get the write answer — 2 so I added two to the answer

Very weired

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

    1 . Yes, $$$r^2 - x^2 - 1$$$ becomes $$$-1$$$ when $$$x = r$$$, then it will become -2147483648 (saw from code), but then you multiply it by 2, so it becomes 0 (because of the overflow).

    You can add this in your loop to check it out for yourself.

    cout << x << " " << (int)sqrt(r*r-x*x-1) << " " << (int)sqrt(r*r-x*x-1)*2 << endl;

    2 . It comes from first (why you need to add 2). When $$$x = ±r$$$, you have $$$\sqrt{2r} - 0$$$ instead of $$$\sqrt{2r} - (-1)$$$, so you loose 1 point for both $$$x = r$$$, and $$$x = -r$$$.

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

In the Editorial Implementation for the problem F, when we say the overall answer is the answer per quadrant multiplied by 4, aren't we over-counting at the edges of the semi-disc (like x=0 or x=r) ?. Could anyone help figure out what I might be missing. Thanks.

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

Shouldn't this editorial be published after the end of hacking phase? [In Educational Rounds and Div3s, I usually don't see Editorials to be published before the end of Hacking Phase]

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

In C, you say "Below is the shortest solution we know of". What about my solution? https://codeforces.me/contest/1971/submission/260294806

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

For Problem C 1971C - Clock and Strings, We can:

1.Perform a,b,c,d = min(a,b), max(a,b), min(c,d), max(c,d)

2.Check if a<c<b and !(c<b<d) then YES else NO

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

If anyone is interested in solving problem H without fully implementing 2-SAT algo, here is a solution.

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

Those who used float/double in E ------------------> :(

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

my submission got hacked it gave wrong answer on test case 21 but when i run that test case on my ide other than that of cf it is giving the expected output . Can somebody help https://codeforces.me/contest/1971/submission/260487849

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

    You are given the whole input of TC21 and it's easy to calculate the real answer by hand, so you should be able to debug what went wrong in your code. The expected answer for the fourth query is: $$$\displaystyle \frac{45 \cdot 2}{6} = 15$$$. Your code produces inaccurate results due to the use of double.

    Basically, you shouldn't use double in this problem. It's very hard to make calculation using double right (there are more tricky edge cases; see hacks). It's possible to solve this problem with just integer arithmetic, which gives precise answers.

»
2 года назад, скрыть # |
← Rev. 5  
Проголосовать: нравится 0 Проголосовать: не нравится

For someone who need a small hack test case for E

Test case
»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

in problem F if we can implement a function g that returns the number of points that have a distance d<r then the answer is g(r+1)-g(r) this function can easily be made with binary search this is my submission 260491421

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

In Problem E ,I submitted the following code : My Submission

but it gives wrong answer on test case : 1 6 1 1 6 45 2

the expected output is 15 but my code's output is 14

When i debug my code, i found that whole error occurs in the line long long ans=floorl(time); bcoz the value of time before was 15 but after taking floorl it became 14.I don't understand why this is happening on my system and also on online judge.Is this a bug of C++ 20?? or i have done something wrong in my code.I have also used fixed<<setprecision(0) to avoid printing of answer in scientific notation like 1e9 instead of 1000000000 . But it does not affect my answer but floorl does. Kindly help me out and explain this unexpected behaviour of floorl which can be used for long double numbers as per documentation.

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

flamestorm can you give solution without using atcoder library of problem H??

»
2 года назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Problem F reminded me of my Computer Graphics course, where we discussed how to draw a circle efficiently on the screen. (It involves avoiding FP computation and replacing multiplication with addition.)

So my solution works as follows. Let point P start at $$$(0, r)$$$. For every step, checks if $$$P$$$ falls in the range. Then, P moves to the right 1 unit, and if $$$|OP| \ge r+1$$$, revert the previous move and move P down 1 unit instead. Repeat until you reach $$$(r, 0)$$$, and multiply the answer by 4.

Code

This algorithm works because the width is 1. The reason why CG introduced this algorithm is that it never requires calculating the $$$|OP|^2$$$ by performing 2 multiplications, but you can instead calculate the increment of $$$|OP|^2$$$ in O(1) additions for each iteration.

»
2 года назад, скрыть # |
← Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

this is my first contest on codeforces...can anybody tell me why i don't get the score yet? i did particitate in the contest during the time it was held.

»
2 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Could someone explain for me this statement from editorial of H:

at least 2 of (x,y,z) are true ⟺ at least one of (x,y) is true, at least one of (y,z) is true, and at least one of (z,x) is true.

I mean, without using truth table

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

    0 true variables is obvious

    if only one variable is true (let it be $$$x$$$) is true, then 2 out of 3 statements will evalutate to true becuase $$$x$$$ is present in two equations.

    but if you turn two variables true (let them be $$$x$$$ and $$$y$$$), then all 3 equations will evaluate to true (2 of which because of variable $$$x$$$ and another one because of variable $$$y$$$ which we couldn't use before)

  • »
    »
    2 года назад, скрыть # ^ |
    ← Rev. 2  
    Проголосовать: нравится +3 Проголосовать: не нравится

    It's tedious but you can obtain that by using the distributive law of boolean logic: $$$a \land (b \lor c) = (a \land b) \lor (a \land c)$$$ and $$$a \lor (b \land c) = (a \lor b) \land (a \lor c)$$$, where $$$\land$$$ means logical "and" and $$$\lor$$$ means logical "or".

    First, the condition "at least two of x, y, z are true" can be translated to: $$$(x \land y) \lor (y \land z) \lor (z \land x)$$$. What we want to prove is $$$(x \land y) \lor (y \land z) \lor (z \land x) = (x \lor y) \land (y \lor z) \land (z \lor x)$$$.

    Let's consider just the first two terms. By the distributive law, we get $$$(x \land y) \lor (y \land z) = (x \lor (y \land z)) \land (y \lor (y \land z)) = (x \lor y) \land (x \lor z) \land (y \lor y) \land (y \lor z)$$$. Since $$$y \lor y = y$$$, and $$$y$$$ must be true in this conjunction, $$$x \lor y$$$ and $$$y \lor z$$$ are always true, thus they are redundant and can be removed. Therefore we get: $$$(x \land y) \lor (y \land z) = (x \lor z) \land y$$$.

    You can derive $$$((x \lor z) \land y) \lor (z \land x) = (x \lor y) \land (y \lor z) \land (z \lor x)$$$ by expanding the expression in a similar manner. I leave this as your homework because I've written too much $$$\TeX$$$ s already :)

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

    Forward implication is trivial since atmost 1 variable can be false.

    Backward implication is also trivial. Assume 2 are false, wlog let them x, y. Then clearly there are 2 things wrong in (x, y) pair. Contradiction

»
2 года назад, скрыть # |
 
Проголосовать: нравится -11 Проголосовать: не нравится

In problem E

include<bits/stdc++.h>

using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds;

// #define ordered_set tree<int, null_type,less, rb_tree_tag,tree_order_statistics_node_update>

define f0r(a, b) for (long long a = 0; a < (b); ++a)

define f1r(a, b, c) for (long long a = (b); a < (c); ++a)

define f0rd(a, b) for (long long a = (b); a >= 0; --a)

define f1rd(a, b, c) for (long long a = (b); a >= (c); --a)

define ms(arr, v) memset(arr, v, sizeof(arr))

define send {ios_base::sync_with_stdio(false);}

define help {cin.tie(NULL); cout.tie(NULL);}

define fix(prec) {cout << setprecision(prec) << fixed;}

define mp make_pair

define all(v) v.begin(), v.end()

define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}

define readgraph(list, edges) for (int i = 0; i < edges; i++) {int a, b; cin >> a >> b; a--; b--; list[a].pb(b); list[b].pb(a);}

define vsz(x) ((long long) x.size())

typedef long long ll; typedef long double lld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector vi; typedef vector vl; typedef vector vpi; typedef vector vpl; typedef long long ll; typedef unsigned long long ull; typedef long double lld;

void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << ''' << x << ''';} void __print(const char *x) {cerr << '"' << x << '"';} void __print(const string &x) {cerr << '"' << x << '"';} void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << '}';} void _print() {cerr << "]\n";} template <typename T, typename... V> void print(T t, V... v) {_print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

ifndef ONLINE_JUDGE

define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

else

define debug(x...)

endif

void solve() { // TODO: Add your code here int n,k,q; cin>>n>>k>>q; vector a(k+1); vector b(k+1);

a[0]= 0;
b[0]= 0;
for(int i=1;i<=k;i++){
    cin >> a[i];
}


for(int i=1;i<=k;i++) {
    cin>>b[i];

}

while(q--){
    int d;
    cin>>d;
    int it = lower_bound(a.begin(), a.end(), d) - a.begin();

    double t2,x2;
    if(d==a[it]){

            cout << b[it] << ' ';
            continue;

    }
    else it--;

    ll ans = b[it];
    ll t = ((d-a[it])*(b[it+1]-b[it])) / (a[it+1]-a[it]);
    // if(ans - int(ans) >= 0.5) ans = int(ans + 1);
    // else ans = int(ans);
    cout << ans + t << ' ';
}
cout << '\n';

}

int main() { #ifndef ONLINE_JUDGE freopen("Error.txt", "w", stderr); #endif send help; int _t;cin>>_t;while(_t--) solve(); return 0; }

ABOVE SOL got accepted

include<bits/stdc++.h>

using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds;

// #define ordered_set tree<int, null_type,less, rb_tree_tag,tree_order_statistics_node_update>

define f0r(a, b) for (long long a = 0; a < (b); ++a)

define f1r(a, b, c) for (long long a = (b); a < (c); ++a)

define f0rd(a, b) for (long long a = (b); a >= 0; --a)

define f1rd(a, b, c) for (long long a = (b); a >= (c); --a)

define ms(arr, v) memset(arr, v, sizeof(arr))

define send {ios_base::sync_with_stdio(false);}

define help {cin.tie(NULL); cout.tie(NULL);}

define fix(prec) {cout << setprecision(prec) << fixed;}

define mp make_pair

define all(v) v.begin(), v.end()

define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}

define readgraph(list, edges) for (int i = 0; i < edges; i++) {int a, b; cin >> a >> b; a--; b--; list[a].pb(b); list[b].pb(a);}

define vsz(x) ((long long) x.size())

typedef long long ll; typedef long double lld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector vi; typedef vector vl; typedef vector vpi; typedef vector vpl; typedef long long ll; typedef unsigned long long ull; typedef long double lld;

void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << ''' << x << ''';} void __print(const char *x) {cerr << '"' << x << '"';} void __print(const string &x) {cerr << '"' << x << '"';} void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << '}';} void _print() {cerr << "]\n";} template <typename T, typename... V> void print(T t, V... v) {_print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

ifndef ONLINE_JUDGE

define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

else

define debug(x...)

endif

void solve() { // TODO: Add your code here int n,k,q; cin>>n>>k>>q; vector a(k+1); vector b(k+1); vector dp(k+1, 0); a[0]= 0; b[0]= 0; for(int i=1;i<=k;i++){ cin >> a[i]; }

for(int i=1;i<=k;i++) {
    cin>>b[i];

}

while(q--){
    double d;
    cin>>d;
    int it = lower_bound(a.begin(), a.end(), d) - a.begin();

    double t2,x2;
    if(d==a[it]){

            cout << b[it] << " ";
            continue;

    }
    else it--;

    ll ans = b[it];
    ll t = ((d-a[it])*(b[it+1]-b[it])) / (a[it+1]-a[it]);
    // if(ans - int(ans) >= 0.5) ans = int(ans + 1);
    // else ans = int(ans);
    cout << ans + t << " ";
}
cout << '\n';

}

int main() { #ifndef ONLINE_JUDGE freopen("Error.txt", "w", stderr); #endif send help; int _t;cin>>_t;while(_t--) solve(); return 0; }

ABOVE got rejected

only difference is the double d and int d in the while loop query can anyone tell me whats wrong

I got hacked my initial cases were passed correctly

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

What is the best way to deal with precision issues when using floating points like in problem E? MY SOLUTION

Thanks in advance

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

Can anyone help me indentifying why my code is giving runtime error for this following code in Problem G: "https://codeforces.me/contest/1971/submission/260600724"

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

    I modified your submission in 2 places. Now it can AC. See submission

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

      Hey thanks, it got an AC. I removed the equality sign from comparator and got correct answer, but still can't figure out why removing equality sign from comparator got an AC.

      • »
        »
        »
        »
        2 года назад, скрыть # ^ |
        ← Rev. 2  
        Проголосовать: нравится 0 Проголосовать: не нравится

        (Disclaimer: my claim has a little bit of rule of thumbs and informal terminologies here, since I was half unsure, half wanting to simplify the topic)

        Normally for programming languages, defined comparator that takes two entities $$$a$$$ and $$$b$$$ should return true if and only if $$$a$$$ should be placed before $$$b$$$, and it will look upon those comparisons returning true to dictate the final order of the list/array.

        Thus if you consider $$$a \le b$$$ as true, and in fact $$$a = b$$$, comparator will take both compare(a,b) and compare(b,a) as true, thus sending those two entities into an endless loop of placing one before another. This part is an undefined behavior, that different compiler implementations will have different responses to this (and in this exact case, most implementations will break your code, either through TLE or RTE).

        Removing equal sign will break that loop, ensuring that the array/list can be sorted in a deterministic way in the comparator's viewpoint.

        • »
          »
          »
          »
          »
          2 года назад, скрыть # ^ |
          ← Rev. 2  
          Проголосовать: нравится 0 Проголосовать: не нравится

          Yes, your point makes lot of sense but if both the "compare" functions should return true, then the compiler should ideally make both the elements stay at their own place. Why it should end in an infinite loop ?

          Like it can also occur in cases when sorting an array with all elements equal

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

            This part, I apologize, I can't explain further, coz' I also don't know in-depth. It's not really supposed to be compiler's doing at this point, but how the sorting algorithm in the library works internally, and it is over my head (usually in a programming language, sorting algorithm is a hybrid of things, so without digging in I can't tell for sure).

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

            A comparator (in c++ atleast) is supposed to return true IFF a should be placed before b. This is the standard of the language.

            By returning true when a = b, you are basically telling the compiler to put a before b, and also to put b before a.

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

Hey, a question regarding problem G (in C++). My code gives TLE when using unordered_map, but is accepted when using map. Why is it so? Most of the time I am using unordered_map and in this case, although the solution is correct, it is a bit of a bummer that it gives TLE (because how would I know that the problem is the use of unordered_map).

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

    I'd assume that there are some tests (either from main or hacking phase) that exploits the hashing algorithm of unordered_map, causing enough collisions to make its operations $$$\mathcal{O}(n)$$$ instead of the average $$$\mathcal{O}(1)$$$.

    map is $$$\mathcal{O}(\log n)$$$ constantly so such tests are harmless to it.

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

For C can anyone find error in my code https://codeforces.me/contest/1971/submission/260905825

  • »
    »
    2 года назад, скрыть # ^ |
    ← Rev. 3  
    Проголосовать: нравится 0 Проголосовать: не нравится

    Mostly precision errors to me.

    A few rules of thumbs:

    • Ditch float, use double and long double when needed. float's fp16 nature has very low precision.
    • Only use floating point numbers when there are no alternatives. Here, as the problem only requires the answer rounded down, you can do everything with int/long long, just make sure you do the correct calculating order (there is only one dividing operation per query, so do it last).
»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

1971H - ±1

Why in the four testcase of problem H, the case 6 1 3 -6 2 5 2 1 3 -2 -3 -6 -5 -2 -1 -3 2 3 1

Say no?, the array [1, 1, 1, 1, 1, -1] doesn't works?

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

Could please someone explain me what is wrong with my 2-SAT implementation for the problem H? My attempt fails on the test 3 with wrong answer: https://codeforces.me/contest/1971/submission/261300539. I guess there should be a problem somewhere in a Tarjan's algorithm implementation, because earlier I used less optimized way to find SCC, and it worked up to test 7, where it timed out.

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

Here's a neat little solution for F, I observed that all points on the circle perimeter are touching one another, so we can just "trace" the circle and bfs every point within the correct distance. Very easy solution when you do it this way.

void solve(){
    int r;
    cin >> r;
    map<array<int, 2>, int> vis;
    queue<ai> q;
    q.push({0, r});
    int ans = 0;
    while (!q.empty()) {
        auto [i, j] = q.front();
        q.pop();
        if (vis[{i, j}]++) continue;
        int sq = sqrt(i*i+j*j);
        ans += (r <= sq && sq < r+1);
        for (int a = -1; a <= 1; a++) {
            for (int b = -1; b <= 1; b++) {
                int new_sq = sqrt((i+a)*(i+a) + (j+b)*(j+b));
                if (new_sq >= r && new_sq < r+1) q.push({i+a, j+b});
            }
        }
    }
    cout << ans << endl;
}
»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hi All,

Can anyone help why this solution is incorrect for problem F

public static void main(String[] args) {
    MyScanner sc = new MyScanner(); 
    out = new PrintWriter(new BufferedOutputStream(System.out));

    int test = sc.nextInt();
    while (test-- > 0) {
      long n = sc.nextLong();

      long count = 0;
      for (long i = n; i > 0; i--) {
        long high = numHigh(((n + 1L) * (n + 1L)) - (i * i));
        long low = numLow((n * n) - (i * i));
        count += high - low + 1L;
      }

      out.println(count * 4);
    }

    out.close();
  }

  public static long numHigh(long sum) {
    long sqrt = (long) Math.sqrt((double) sum);
    return sqrt * sqrt == sum ? sqrt - 1L : sqrt;
  }

  public static long numLow(long sum) {
    long sqrt = (long) Math.sqrt((double) sum);
    return sqrt * sqrt == sum ? sqrt : sqrt + 1L;
  }
»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

My solution to C with neural network: 265483456

The parameters are trained with Tensorflow and then I hand-craft the code to run this model because we cannot import numpy on cf.

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

Hey , In problem G I forget about lexicographical order and i don't see something in the code that assures it , why is it working ?? We didn't even add a comparator on the pq ?

»
2 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

getting TLE on H: https://codeforces.me/contest/1971/submission/268388372

using an adjacency list to construct the implication graph, then running DFS(x, !x) and DFS(!x, x) for each variable x.

EDIT: I stopped resetting my visited vector in between DFSs. Unsurprisingly, this made my code run faster, but I'm not sure how it got accepted. Shouldn't having nodes marked as visited (which actually haven't been visited) result in WA?

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

Ok

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

1971H - ±1 can use bruteforce solution to solve (O(N^2)) 269428997

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

problem E,i can never know what mistake i've made! HELP![submission:274632531]

»
2 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

I have no idea that int keys in python dictionary cost so much time in problem G

279007510 used int keys and got TLE

279008366 used str keys and only used half the time