Thank you for participating!

Idea: mesanu

**Tutorial**

Tutorial is loading...

**Solution**

```
#include <bits/stdc++.h>
using namespace std;
void solve()
{
int a, b, c;
cin >> a >> b >> c;
cout << (a+b+c-min({a,b,c}) >= 10 ? "YES\n" : "NO\n");
}
int main()
{
int t;
cin >> t;
while(t--)
{
solve();
}
}
```

Idea: flamestorm

**Tutorial**

Tutorial is loading...

**Solution**

```
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200007;
const int MOD = 1000000007;
void solve() {
int n;
cin >> n;
int winner = -1, best_score = 0;
for (int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
if (b > best_score && a <= 10) {winner = i; best_score = b;}
}
cout << winner << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve();}
// solve();
}
```

Idea: flamestorm

**Tutorial**

Tutorial is loading...

**Solution**

```
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200007;
const int MOD = 1000000007;
void solve() {
for (int r = 0; r < 8; r++) {
for (int c = 0; c < 8; c++) {
char x;
cin >> x;
if (x != '.') {cout << x;}
}
}
cout << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt; cin >> tt; for (int i = 1; i <= tt; i++) {solve();}
// solve();
}
```

Idea: SlavicG

**Tutorial**

Tutorial is loading...

**Solution**

```
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
void solve() {
int n, k; cin >> n >> k;
vector<int> a(n);
for(int i = 0; i < n; ++i) cin >> a[i];
sort(all(a));
int cnt = 1, ans = 1;
for(int i = 1; i < n; ++i) {
if(a[i] - a[i - 1] > k) {
cnt = 1;
} else {
++cnt;
}
ans = max(ans, cnt);
}
cout << n - ans << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
cin >> t;
while(t--) {
solve();
}
}
```

1850E - Cardboard for Pictures

Idea: flamestorm

**Tutorial**

Tutorial is loading...

**Solution**

```
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
#define int long long
void solve() {
int n, c; cin >> n >> c;
vector<int> a(n);
for(int i = 0; i < n; ++i) cin >> a[i];
int l = 1, r = 1e9;
while(l <= r) {
int mid = l + (r - l) / 2;
int sumall = 0;
for(int i = 0; i < n; ++i) {
sumall += (a[i] + 2 * mid) * (a[i] + 2 * mid);
if(sumall > c) break;
}
if(sumall == c) {
cout << mid << "\n";
return;
}
if(sumall > c) {
r = mid - 1;
} else {
l = mid + 1;
}
}
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
cin >> t;
while(t--) {
solve();
}
}
```

**Tutorial**

Tutorial is loading...

**Solution**

```
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
void solve() {
int n; cin >> n;
vector<ll> cnt(n + 1, 0), mx(n + 1, 0);
for(int i = 0; i < n; ++i) {
int x; cin >> x;
if(x <= n) ++cnt[x];
}
for(int i = 1; i <= n; ++i) {
for(int j = i; j <= n; j += i) mx[j] += cnt[i];
}
cout << *max_element(all(mx)) << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
cin >> t;
while(t--) {
solve();
}
}
```

Idea: flamestorm

**Tutorial**

Tutorial is loading...

**Solution**

```
#include <bits/stdc++.h>
#define startt ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
using namespace std;
#define vint vector<int>
#define all(v) v.begin(), v.end()
#define int long long
void solve()
{
int n;
cin >> n;
map<int, int> up, side, diag1, diag2;
int ans = 0;
for(int i = 0; i < n; i++)
{
int x, y;
cin >> x >> y;
up[x]++;
side[y]++;
diag1[x-y]++;
diag2[x+y]++;
}
for(auto x : up)
{
ans+=x.second*(x.second-1);
}
for(auto x : side)
{
ans+=x.second*(x.second-1);
}
for(auto x : diag1)
{
ans+=x.second*(x.second-1);
}for(auto x : diag2)
{
ans+=x.second*(x.second-1);
}
cout << ans << endl;
}
int32_t main(){
startt
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
```

Idea: SlavicG

**Tutorial**

Tutorial is loading...

**Solution**

```
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
#define int long long
const int N = 2e5 + 5;
vector<pair<int, int>> adj[N];
int val[N], vis[N];
void dfs(int u) {
vis[u] = 1;
for(auto x: adj[u]) {
int v = x.first, w = x.second;
if(!vis[v]) {
val[v] = val[u] + w;
dfs(v);
}
}
}
void solve() {
int n, m; cin >> n >> m;
for(int i = 1; i <= n; ++i) {
adj[i].clear();
vis[i] = 0, val[i] = 0;
}
vector<array<int, 3>> c;
for(int i = 1; i <= m; ++i) {
int a, b, d; cin >> a >> b >> d;
adj[a].pb({b, d});
adj[b].pb({a, -d});
c.pb({a, b, d});
}
for(int i = 1; i <= n; ++i) {
if(!vis[i]) dfs(i);
}
for(int i = 1; i <= m; ++i) {
int a = c[i - 1][0], b = c[i - 1][1], d = c[i - 1][2];
if(val[a] + d != val[b]) {
cout << "NO\n";
return;
}
}
cout << "YES\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
cin >> t;
while(t--) {
solve();
}
}
```

It feels like Problem A was directed at someone 😶

It is easy to write verses

When you have not what to tell,

Stinging words and hollow phrases

In a gangling doggerel.

Thanks to authors! The problemset was very cool

me too

I enjoyed the problems

This competition is the best for me.

The best competition for me is this one.

For E wasn't it worth mentioning O(1) solution with quadratic formula if we ignore time for taking input

https://codeforces.net/contest/1850/submission/214907399 or https://codeforces.net/contest/1850/submission/214911845

sqrt is log(n), so in fact there are no O(1) solutions

can u explain how can i get 128 bit integers working on my local compiler?

because your computer dose not have a 64-bit compiler.

128-bit int works only on 64-bit compilers.

its not working though

sorry i mean u don't have 64-bit compiler

You can use TDM-GCC compiler 64 bit. It supports both 32 and 64 bit. Regardless, I will suggest you to use python. TDM-GCC -> Download here

calculating the sum takes O(N) time

heh) I saw the problem and immediately thought about binary search and solving the equation. I decided to choose the second one and as a result I first wrote the code for pluses, and then for python (I never used int128)

Hey, How come you have reached to this solution? Can you please explain about your quadratic formula approach

A painting with side s_i requires a cardboard square with side (s_i + 2*w).

The total area of the cardboard squares (the c input in the problem) is:

The last equation is quadratic in terms of w and we can solve it using the quadratic formula

EDIT: Thanks for the correction aryang22

Nice, using commutative and associative properties of sigma, but It didn't clicked to me. This proves how silly I am :(

I guess there should be a bit of correction in the last line:

Here, n = number of pictures. If you see this for 1st test case, 3 and 50 and {3,2,1}, so

`sum(s_i^2) = 14`

,`c = 50`

,`sum(s_i) = 6`

, and`n = 3`

. If you put`w = 1`

, it satisfies only if you consider`n`

also, that is,LHS:

`14-50+4*6*w+4*w^2*3`

=>`14-50+24*(1)+12(1)^2`

=>`-36+36`

=>`0 = RHS`

Yeah, absolutely. That should have read sum(4*w^2) which is just equal to 4*w^2*n as you point out, since it does not depend on the summation index.

my solution using quadratic formula https://codeforces.net/contest/1850/submission/214937317

tried yours in mine, why does it gives compilation errorcode

It will not compile on 64 bit system. It is using __int128 which is of 128 bit

I used c++20

I tried doing like that in C++ but didn't get around precision values

Yeah long double was not going to cut it

That’s what i did, had problems with the output for large numbers tho, but it’s O(n), not O(1), instead of O(nlogn)

For anyone using JAVA , never ever use Arrays.sort even after shuffling the array, I got unnecessary TLE and rectified using Collections.sort. The tests were designed carefully.

thanks

Yes as Arrays.sort uses counting sort versus Collections.sort implements merge

No, Arrays.sort uses dual pivot quick sort, whose worst time complexity can go O(n^2).

What is a failed test case for this solution for D?

214942704

I make the same code and i do not know where is the wrong

Editorial published during open hacking phase?!

G Problem is kind of impossible with python

Even if we forget the fact that there are workarounds to the hash hack in python, we can still solve the problem using python quite easily.

Instead of using maps/dictionaries, we can just store all values of $$$x$$$, $$$y$$$, $$$x + y$$$ and $$$x - y$$$ in four separate arrays, sort each of them and check the number of equal elements that way. And as far as I know, there is no hack for sorting in python (unlike in java).

Code (pls forgive me for horrible python): 214952260

thanks got it now sorting also a good option

i got hacked on G (tle) because for some reason i thought i had to sort the points in order to get the intersection with y = x+c and y = -x + c lines.

It turns out this is unnecessary and you can solve the question with linear time O(N).

HACKED submission O(Nlog(N))

O(N) submission

Bro, it's TL unfortunately

https://codeforces.net/contest/1850/submission/214868771 This code look sus. Is it allowed?

That is (quite obivously) code obfuscation, which is not allowed. Hopefully they'll get skipped for breaking rules.

what does code obfuscation mean?

If only there was some magical place where you could just type the words "what does obfuscation mean" and you'd get an answer instantly...But how many defines is code obfuscation then? Some c++ solutions are absolutely unreadable even though their authors had no intention to muddle their code.

I don't think there are any specific numbers I can give; I think the more important part is intention:

If the author didn't intend to make the code unreadable (and they can read it themselves), I wouldn't call it obfuscation.

If the author

deliberatelymade the code unreadable (possibly using automated help), I would definitely call it obfuscation.I think it should be clear that the aforementioned code falls under the second case.

Unfortunately I saw a lot of solutions with defines like this that make the code unreadable. But I don't really know what to do with that as I haven't found any flag/signal. button yet.

I think the only reason you said this is because you cheated.

Could you elaborate?

Please ban him MikeMirzayanov

Of course, this is an obvious violation of the rules, and the user will be punished.

lesss gooo !

Can you see the message that I sent you. Please coach

What the hell lol.. he seems too scared of being hacked

Hello! This is my first contest and I submitted the problem A. I was registered but I do not see an increase in my rating, can someone tell me when will I get them?

check again tommorrow afternoon (indian time)

can someone try to hack my solutions?

I used binary search for problem-E but it has some error which I am unable to figure out. Can anyone please help me find error in my binary search logic for my submission 214950555. ? edit : when i set

`r = 1e10`

the sample test-cases passed but on submission it fails again on some test case.it looks like the res function might overflow, I had that problem and dealt with it as explained in the editorial. you can also use __int128 instead of long long to avoid overflow.

try r=sqrt(c) , it's the smallest value of r that can be valid

true, an alternative is also to use r=1e9+1.

Thanks for this round. The round was very enjoyable!

Why this solution TLE in problem F because It does unnecessary work when we have more occurrences of one elment. I think the TC Is exactly the same as the one proposed by the editorial in the end. Also if we have the test case 1,2,3....,2e5. The solution posted does the same number of operations as the one of the editorial. Am I wrong thinking that this has the same TC as editorial?

If all n values of ai are equal to 2, each one will need n/2 iterations, in total n*n/2 operations.

Therefore it is necessary to treat together the array values that are equal.

maybe f can be hacked, consider case {1,1,1...} * 10^5

this prevents it.

i think E problem's optimal solution O(N) my submission

I liked problem H . Before reading editorial, i didn't though it will turn that easy.

can someone explain why my E solution is accepted here:

https://codeforces.net/contest/1850/submission/214991383

but it is failing here:

https://codeforces.net/contest/1850/submission/214991353

the only difference is in my accepted version, i did (sizes[i] + w * 2) * (sizes[i] + w * 2)

but in the failing version, i did pow((sizes[i] + w * 2), 2)

Check this blog: https://codeforces.net/blog/entry/21844

thanks!

Can someone help me understand why my solution for G got hacked? I have written same code as tutorial. https://codeforces.net/contest/1850/submission/214891422

Because you are using unordered map which has a worst case time complexity O(n). Read this for more information:https://codeforces.net/blog/entry/62393

Thanks, I never considered this issue. I guess just stick to map unless unordered_map is really required.

Really a very good, balanced, and learning contest for beginners.

Thanks to the Author.

In this contest can my E be WA, G be TL?

My submission in E in contest: 214829184. I don't know how it's passed pretests. In code wrongly I did: x = s[i] + 2 * md + 1 and printed l but x should be s[i] + 2 * md and printed l — 1. Like this code: 214997775 which I submitted after contest. Please let me know if it's hackable.

My submission in G in contest: 214869824. Can it be TL or ML? It passed pretests with 1668 ms 76900 KB(Time limit is 2s). After contest I optimized it (removed set) and passed pretests with 904 ms 39300 KB(214997753). Please let me know it's hackable.

Very good problem set. Thanks to all the people who were involved in organizing this round.

can you guys pls explain to me how not to get integer overflow in my submission?

https://codeforces.net/contest/1850/submission/215016417

Someone suggested me to use long double and it worked. While printing the value, typecast it into long long to get the desired format

I was wondering if someone used Newton Raphson method for solving E?

I doubt it, it's too overkill for a problem like this.

During the contest,I misunderstand Problem F,I think each second we can place a trap,so in this case,can we also calculate the maximum number of the frogs we can catch?I need help,thanks.

Nice round , I hope all next rounds(div4) will be on this level

Hello, during the contest I submitted this code which got accepted, but after that my code go from accepted to "In queue", can anyone explain? Thank you

Here's the link to the code: https://codeforces.net/contest/1850/submission/214905784

It is just getting reevaluated

Can anyone help me my code has resulted in TLE in system testing?, it is having similar complexity as of author O(nlogn)

CodeYour code does about this many iterations $$$\sum_{x=1}^{n}\sqrt{x}$$$, but the TLE is probably because you are using unordered map, i advise you to read this article:https://codeforces.net/blog/entry/62393.

Your code is $$$O(n^2)$$$ because of unordered_map

MikeMirzayanov Unlike the original contests/exams in real life,can I get assistance from external websites while doing a contest? I mean it's quite easy,I have seen it. I am doubting a lot

please answer my question

The solution of F was already available on geeks for geeks and other various websites , seems to be a quite popular problem

how does my morning star submission got hacked I did the same thing said in the tutorial lol

No offense, but you are the millionth person already asking the same question. It is because you used unordered map which can be hacked easily if you don't use a custom hash. Read this article for more information:https://codeforces.net/blog/entry/62393.

none taken haha, thank you tho.

I used an unordered map on F. I will never use an unordered map again.

Why does that give

TLEif unordered_map is used instead of the normal map in C++? Can anyone tell me when to use unordered_map and normal map?https://codeforces.net/blog/entry/62393

Can anyone explaine how Wrapper function works? This is my hacked submission: https://codeforces.net/contest/1850/submission/214906792 And then i fixed it by Wrapper function which make my submisson accept https://codeforces.net/contest/1850/submission/214984466 *sorry for bad english

can someone tell why Question 'G' Fails for an Unordered map, but runs absolutely fine for ordered map

void mr_kamran(){

ll n; cin>>n; ll ans = 0; unordered_map<ll,ll>m1,m2,m3,m4; for(int i = 0;i<n;++i) { ll x,y; cin>>x>>y; m1[x]++; m2[y]++; m3[y-x]++; m4[y+x]++; } for(auto it : m1) { ans+=(it.second*(it.second-1)); } for(auto it : m2) { ans+=(it.second*(it.second-1)); } for(auto it : m3) { ans+=(it.second*(it.second-1));

} for(auto it : m4) { ans+=(it.second*(it.second-1)); } cout<<ans<<an;

}

Check the editorial, this question has been answered a million times here.

https://codeforces.net/blog/entry/62393

Just asked on StackOverflow: https://stackoverflow.com/questions/76745525/why-does-using-unordered-map-give-tle-but-map-is-ac-for-codeforces-886-div

Hasn't been answered yet.

there might be some internal collisions due to the internal implimentation of unordered maps

COULD ANYONE PLEASE EXPLAIN WHY USE OF THE QUADRATIC FORMULA IS NOT WORKING IN E PROBLEM?

can someone help me to optimize this solution for G problem:

https://codeforces.net/contest/1850/submission/215083504

Regarding Maths solution for E problem

Why I get compilation error for this solution: https://codeforces.net/contest/1850/submission/215091151

but this other solution works: https://codeforces.net/contest/1850/submission/214911845

im going crazy, literally same thing

Pleasse help someone

Solved problem H using Union Find.

215052919

Hello, guys, could you share some useful resources about harmonic series, especially how it can be used in solving cp problems?

is it possible to solve problem G with dp ?

can anyone tell me how this code doesn't work problem E https://codeforces.net/contest/1850/submission/215107429

why my solution isn't working on 2 test case in problem B. code

Consider the case when first pair was 11 and INF . your answer won't get updated

isn't that what the problem wants, not to get updated if > 10 is first value

well , you are assuming that the v[0].first will not be greater than 10.

well, i am using &&(AND) so it should'nt get updated

You gave the variable mx value 0 before even checking v[0].first is less than 11 or not . Change both ans and mx to -1 and it should pass

it worked. Thanks, learnt the lesson.

Code1850E - Картон для картин

Can someone Explain Why my code gives WA? For Some Test Cases it the While Loop Breaks and prints 1 which I used for Checking.

in your predicate function (s) 'ans' variable is overflowing.

to combat this return ans as soon as it becomes larger than c

ll s(ll md, vector &v) { ll ans = 0; for (ll i = 0; i < v.size(); i++) { ans += ((v[i] + 2 * md) * (v[i] + 2 * md)); if(ans>c) return ans; } return ans; }

Thanks, It worked!!

How did you spot it?

like md is 1e9 now you square it becomes 1e18

now you are adding it a maximum of 1e5 times

so 1e18 X 1e5 will give you 1e23 — overflow

Nice!

Problem E was headache for beginners. Handling large int values...ahhh!

why F is nlog(n)? if there are 2e5 1 than is n*n

hash the count of each number

so even is there are 1e5 1s the answer will run in n

I don't think they say that in this problem .Is there a hint here? It is guaranteed that the sum of n over all test cases does not exceed 2⋅105

i did not get your point sorry lol

the problem f isn't say hash the count of each number.

you just have(can ig) to do it in order to solve it lol

sorry ig our views differ due to our solutions

but i also n't understand

In the case {1,1,1,1,1,1 } You only need to consider the number 1 only 1 time. So basically what you do is that you store the frequency of 1 (6 in this case), and then loop only one time instead of 6. After each iteration, you add 6 to all the factors of 1, denoting that 1 will visit position i 6 times.

Hope you got the idea.

Why all the downvotes?

It looks like n*n but it's not. the time complexity is n+n/2+n/3+n/4+n/5 +... We can factor out n and it becomes n(1+1/2+1/3+1/4 + .... + 1/n) which you should be familiar with if you have taken calculus. It's called the harmonic series. If you aren't familiar with calculus, all you need to know is that 1+1/2+1/3+1/4 + ... + 1/n is approximately equal to log(n) where n is the number of terms

thank you so much.I get it

why in problem G it gives TLE error if we use

unordered_map<int,int>instead ofmap<int,int>. The time complexity of unordered_map isO(1)whereas operations on map takeO(log n)time.https://codeforces.net/blog/entry/50626?#comment-345515

Thank you for the link! Got the same problem today.

problemset was so cool but i think the "word on the paper" problem was too easy for problem C

For problem H dfs gives me runtime error, and

sol2 sol is getting accepted, Can someone explain me why??

Hey guys! Can somebody help me please why in task E — Cardboard for Pictures we should use mid = l + (r — l) / 2? I am new at this and would appreciate any answer)

It's same as mid=(l+r)/2 but it's recommended to use mid=l+(r—l)/2 to avoid overflow.

Thanks a lot!

In H if there is a cycle can one of the 2 paths give us correct coordinates and another one not.Like can this be a case?

How to approach problem F if condition would have been that we place one new trap each second unitl game conitnues. Thanks In advance

Nice problems but i got minus xD

easy problem

SlavicG Can you explain why u also pushed negative edges in the last problem

G — The Morning Star: In this problem, I received a "Time Limit Exceeded" error while using unordered_map, but it was accepted when I used map. However, I believe that unordered_map is faster than map, so why did the opposite happen here?

I wrote this code in C for problem F 216397398 It shows [Time limit exceeded on test 9]. I can't figure out the problem. Can someone please tell me the problem and how to solve it?

Can we solve H using different approach?: For all loops found in graph, I check if "cnt" of the loop is equal to 0. "cnt" of the loop is sum of all (-d)s for all adjacent vertexes in the loop. For example, if we have loop

(a, b, d)

1 2 1

2 3 2

3 1 -3

cnt of this loop is 0. (-1-2-(-3) = 0). If cnt of the loop is not zero, it means that every soldier in the loop belongs to 2 different camps. My code gives WA3: 216588864

can someone explain how time complexity in problem F came out to be O(nlogn).

this is how i am calculating. for each i — we run the nested loop (n/i) times. so O(i)*O(n/i) = O(n).

where am i wrong here ?

PS: got it.

it should be sum_(i goes from 1 to ) (n / i) = n/1+n/2+n/3+...+n/n = n(1+1/2+1/3...+1/n) = nlogn

can we do F by checking for cycle ?

Comment on G implementation

If you want to calculate $$$n(n-1)$$$, you can instead calculate $$$2(1+2+...+(n-1))$$$.

By using this, you can avoid the second calculation pass and have a cleaner solution (https://codeforces.net/contest/1850/submission/221488328)

I want to ask why I'm using python3 runtimeerror in test 30,https://codeforces.net/contest/1850/submission/221637571 this is my code

can anybody please tell me a counter test case for F problem according to my code? please

CodeI have no idea why B problem (case 2) isn't passing. Here's my code https://pastebin.com/31yfYzrV

For part E, f(x) = sum of squares of s + 4*w*(w*n+sum of s). You can verify this by expanding each bracket in f(x). Both the sum of squares of sum and the sum of s can be computed in O(n) time only once, and then used to calculate f(x) in each binary search iteration in O(1). So in total, you perform one O(n) operation and one O(log n) operation. If you want, you can view my submission at code 239192984.

I wonder why the G question times out with unordered_map

Here you go

Thank you! I get it.

Solved F

What a beautiful problem!

can Anyone SlavicG please tell why my solution for problem H is giving TLE

258450042

I have doubt on using map<pair<ll,ll>,ll> me;

I have been searching on codeforces blog for what may be the problem but unable to find

I tried searching for constant factor TLE blogs but unable to find so can anyone kindly tell what is wrong

According to me time complexity is O(nlogn) where n= m (the number of conditions given in problem)

I think my solution logic may be wrong but then also want to know what thing is the leading to TLE as I have encountered similar TLE problem previously in some different question also

Interestingly in G, if you were to make a map of ints and do diag1 [y-x]++, it will give you wrong answer at test case 12, but the same with diag1 [x-y]++ gives an accepted solution. Note that both these cases work when you make a map of long long.