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

Автор Kogut_Ivan, 18 месяцев назад, По-русски

Мы надеемся, что вам понравился контест! Спасибо вам за участие! Для нас это первый официальный раунд, поэтому мы были бы рады услышать ваши отзывы в комментариях и в мини опросе ниже.

Как вам контест?
Какие задачи вам понравились (можно выбрать несколько)?
Какие задачи вам не понравились (можно выбрать несколько)?

2093A - Идеальный генератор

Идея: EzikBro

Подсказка 1
Подсказка 2
Разбор
Решение

2093B - Дорогое число

Идея: gravitsapa

Подсказка 1
Подсказка 2
Подсказка 3
Разбор
Решение

2093C - Простое повторение

Идея: pskobx

Подсказка 1
Подсказка 2
Подсказка 3
Разбор
Решение

2093D - Кайфовая таблица

Идея: fstilus

Подсказка
Разбор
Решение

2093E - Мин макс мех

Идея: Boodoochai

Подсказка 1
Подсказка 2
Разбор
Решение

2093F - Хакеры и нейросети

Идея: _icy_

Подсказка 1
Подсказка 2
Подсказка 3
Подсказка 4
Разбор
Решение

2093G - Укоротить массив

Идея: EzikBro

Подсказка 1
Подсказка 2
Подсказка 3
Разбор
Решение
Разбор задач Codeforces Round 1016 (Div. 3)
  • Проголосовать: нравится
  • -22
  • Проголосовать: не нравится

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

Are we just gonna ignore the hacks on E on n(logn)² solutions?

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

For problem F, can someone rewrite the problem statement in a simpler way?

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

    You can perform two kinds of operations. Operation 2, i.e, replace any index (1 to n) with a blank is a definite operation, the hackers can choose the index to turn into a blank. However, for operation 1, you can only choose a neural network (1 to m), and any random BLANK index converts to its corresponding string.

    So, we first remove the randomness by choosing the vector with most commonality (comm) with target. So, we definitely have the correct elements in comm positions, if we choose the neural network n times, and definitely the wrong elements in n-com positions. Now, we use 2 operations per (n-com) positions to convert to blank, and then fill it with a string of our choice. Remember, its only random if there are multiple blanks.

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

D. In the fourth possible position, isn’t it y > 2^(n-1) instead of <?

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

bro on E, I did an n*log(n) solution and it got TLE, like tf??? 314610668, (in the contest it pased but in system testing it got TLE on test 32)

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

I think the editorial is not in English.Anyone facing the same issue?

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

Can anyone help me out why my solution failed on E, isnt the time complexity is $$$O(n (\log n)^2)$$$ why would it fail? link

Also the editorial is not in english, please do the needful. Kogut_Ivan

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

Can you please rejudge my solution for E, as some people's code is rejudged again after getting TLE initially, so please rejudge mine as I was at 500 rank before testing. Plsss!!!!

Example: https://ibb.co/jvZTtsT8 (Accepted) https://ibb.co/v44cYddP (TLE)

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

Strange round, difficult D but easy enough E. Still thanks for the tasks and the new experience

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

What is wrong in this submission ??

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

Can someone try uphacking my E? It passes in 1999ms

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

Does E have any $$$O(N)$$$ solutions ? I thought about some greedy picking but the case

$$$n = 10$$$, $$$k = 3$$$

$$$a = 1, 0, 0, 1, 1, 1, 0, 0, 0, 2$$$

is a good counterexample.

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

Should we overlook the innovative approaches applied to E within n(log n)² solutions? These techniques merit a closer examination for their potential to optimize performance and address complex computational challenges effectively.

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

Just disappointed with the E verdict even after writing the solution for O(n log^2 n) time complexity.

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

Боже, юзая map в E получаешь TL, ассимптотика O(n*logn^2)

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

Bad Problem Statement for F

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

For problem E, anyone who gets TLE because of using the unordered map could try using a custom hash. This code comes from here.

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

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

Are you sure you didn't reverse D-E-F?

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

D. what number will be in the cell at the x-th row and y-th column;

x-th row and y-th column? blasphemy.

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

swap D and F please i started from F and then did E then moved to D and was flabbergasted and left the contest (because i was hungry also).

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

Can someone help me with my submission 314773349 for D ?

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

Hi, can anyone explain me why my code get TLE. Its $$$O(nlog(n))$$$ 314779695 not even $$$nlog^2$$$

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

for G you can also do two pointers on a Trie

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

    Could you explain your approach?

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

      hopefully this explanation isn't so horrible:

      denote a set $$$S$$$, notice that $$$\max(a \circ b)$$$ for two elements $$$a, b \in S$$$ is increasing when we add elements to $$$S$$$ and decreasing when we remove elements.

      also given a set $$$S$$$ you can use a Trie to find an element $$$x \in S$$$ such that $$$a \circ x$$$ is maximized for a given $$$a$$$.

      this enables you to do two pointers, you move the right pointer if the greedy algorithm stated above returns $$$x$$$ such that $$$s_r \circ x \lt k$$$ and insert $$$s_r$$$ into to the Trie, else we remove $$$s_l$$$ and move the left pointer, the complexity sums up to $$$O(n \lg max(a_i))$$$ or $$$O(32 \cdot n)$$$

      not my code: 314691768

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

getting TLE in test case 4 in problem D with this recursive solution....can anyone help me


#include <bits/stdc++.h> using namespace std; long long solveCoords(int n, long long start,int row, int col, int& i, int& j,int len){ if(n==1){ if(row==i && col==j) return start; else if(row+1==i && col+1==j) return start+1; else if(row+1==i && col==j) return start+2; else return start+3; } long long total = len*len; long long subTotal = total/4; int x = len/2 -1; int y = len/2 -1; if(i<=row+x && j<=col+y) return solveCoords(n-1,start,row,col,i,j,len/2); x = len/2; y = len/2; if(i>=row+x && j>=col+y) return solveCoords(n-1,start+subTotal,row+x,col+y,i,j,len/2); x = len/2; y = len/2-1; if(i>=row+x && j<=col+y) return solveCoords(n-1,start+2*subTotal,row+x,col,i,j,len/2); x = len/2-1; y = len/2; if(i<=row+x && j>=col+y) return solveCoords(n-1,start + 3*subTotal,row,col+y,i,j,len/2); return -1; } pair<int,int> solveNum(int n, long long start, int row, int col, long long& d,int len){ if(n==1){ if(d==start) return {row,col}; else if(d==start+1) return {row+1,col+1}; else if(d==start+2) return {row+1,col}; else if(d==start+3) return {row,col+1}; } long long total = len*len; long long subTotal = total/4; if(d < start + subTotal) return solveNum(n-1, start, row, col, d, len/2); // Q0 else if(d < start + 2*subTotal) return solveNum(n-1, start + subTotal, row + len/2, col + len/2, d, len/2); // Q1 else if(d < start + 3*subTotal) return solveNum(n-1, start + 2*subTotal, row + len/2, col, d, len/2); // Q2 else return solveNum(n-1, start + 3*subTotal, row, col + len/2, d, len/2); // Q3 } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t; cin>>t; for(int i=0;i<t;i++){ int n,q; cin>>n>>q; int len = 1<<n; for(int j=0;j<q;j++){ string s; cin>>s; if(s[0]=='-'){ int x,y; cin>>x>>y; int i = x-1; int j = y-1; cout<<solveCoords(n,1,0,0,i,j,len)<<endl; } else{ long long num=0; cin>>num; auto it = solveNum(n,1,0,0,num,len); cout<<it.first+1<<" "<<it.second+1<<endl; } } } }
  • »
    »
    17 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +1 Проголосовать: не нравится

    I looked into your code. The main issue was in how you calculated the quadrants—your offset logic wasn’t dividing the matrix correctly, which led to unnecessary recursive calls. Heres the fixed solution : 314840363.

    P.S. Try to use long long for every variable where large values are expected. Otherwise, always make sure to check whether a sum or product could exceed the int limit. Even if your logic was correct, you would have still received a penalty for calculating total = len * len, since len was an int.

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

There's yet another "solution" for G: 314828750.

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

This happened because SO many solutions used an unordered_map or unordered_set and they are very good targets to hack because normally they take $$$O(1)$$$ but in the hash collisions, they can take $$$O(n)$$$. So many people tried to hack these solutions and got successful, so AC solutions during the contest get TLE's when retested after hacks, even when your solution was not targetted. This is extremely disappointing for so many contestants who passed the pretests but after the hacking phase, boom! So many TLE's you can't imagine. I'm not lying, just go to HACKS then Successful hack. You will so many TLE hacks on just problem E. I first tried using normal set during a virtual contest for safety with bin-search 314714290, which was supposed to take $$$O(nlog^2n)$$$ and that is around $$$7 \times 10^7$$$ operations and pass, but I got TLE sadly. Then, I tried bool array like the editorial and after some time, I finally cracked it in $$$O(n log n)$$$ time in just 140 ms 314722830. I think you guys should use unordered maps or sets when and only when you are very sure about the hash collisions (even if pretests pass) and also, for safety, have a normal map or set solution, which are very unlikely to get hacked, unless the $$$log n$$$ factor is really bothering.

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

D is a great problem to learn recursion better.

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

I am having trouble finding the case of TLE in my code for problem G. Could anyone help me out?

314875046

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

    I sorted the issue. Got to know that using objects(pointers) instead of flatenning the trie was the issue. Here's the corrected code if anyone wishes to see:

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

My O(n lg n) solution is failing, is it due to my CP template?

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

Editorial for question C says "It is also possible to precompute prime numbers" but since the X was up to 10^9, precomputing and storing 10^9 values isn't possible, so how can that be done?

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

    Maybe "precompute" is not the best word. They mean to manually check the repunit numbers (i.e. $$$1, 11,\ldots, 111111111$$$) and hardcode the solution.

    Fun fact, after $$$11$$$, the next repunit prime has 19 ones: https://oeis.org/A004023

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

    You dont need to use Sieve of Eratosthenes, see here Sieve of Eratosthenes is used to find all the primes in a certain range but in this question you dont need all the primes in a range instead what you need is simply to find a certain number is prime or not

    for that you can iterate all the divisors till square root of the number and check if there is a divisor other than 1 and the number itself

    Here you can check this code

    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return true;
        }
    }
    return false;
    

    here lets say your number is n so i am just checking if a number greater than 1 can devide n.

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

I really liked the contest, solved five problems by myself in the contest time, and after that learned new ideas and solved the rest of the problems by peeking into the video tutorial (learned about a trie in G and that you can use the binary search method to find the value in question in E). So for me the contest was very educational.

But I'm writing this post to express my unpopular among these comments opinion about problems D and F. For me these problems were exactly what I've always liked about the contests in the past — when the problem can be solved just by coming up with an idea and clear coding instead of pasting one of the miriad data structures or reusing ideas from a similar problem that you've seen before. I like it when you don't need to have such specific knowledge in order to solve a problem.

So I personally would like to see more problems like D and F, even though I can see that a lot of people had trouble with them for some reason.

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

Why is my solution of F with persistent trie TLE 314962660? but if I use another binary search method, it got ac 314958098. it seems that, for any test case, the two kinds of binary search call query function the same times? it's weird, can anyone tell me why my first binary seach is bad.

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

why am i getting TLE on test case 26 for problem E . while the logic of my code is similar to that of editorial. Anyone help please .

my submission : 315084707

any suggestions please.

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

If you’re getting WA2 (291st numbers differ) on problem G, the bug is probably in how you pick the maximum index. You need to take the maximum over all indexes for cases where k′ᵢ = 0 and xor′ᵢ = 1.

Test case from the statement:
»
9 месяцев назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

Why is my solution got wrong for problem G, I have taken all the case

#include<bits/stdc++.h>
#define ll long long
using namespace std;

ll cal(vector<ll> & ai, ll las, ll k){
	ll ans = ai.size() + 1;
	map<ll, ll> cnt;
	for(ll i = 0; i < ai.size(); i++){
		ll x = (ai[i] >> las) & 1;
		ll st = 1;
		if(x){
			for(ll j = las - 1; j >= 0; j--){
				ll x1 = (k >> j) & 1;
				ll ta = (ai[i] >> j) & 1;
				if(x1){
					st = ((st << 1) | (1 ^ ta));
				}
				else{
					ll tem = ((st << 1) | (1 ^ ta));
					if(cnt[tem])ans = min(ans, i - cnt[tem] + 2);
					st = ((st << 1) | ta);
				}
			}
			if(cnt[st])ans = min(ans, i - cnt[st] + 2);
		}
		else{
			for(ll j = las - 1; j >= 0; j--){
			    ll ta = (ai[i] >> j) & 1;
			    st = (st << 1) | ta;
			    cnt[st] = i + 1;
			}
		}
	}
	return ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	ll t;
	cin >> t;
	while(t--){
		ll n, k;
		cin >> n >> k;
		vector<ll> ai(n);
		for(auto & i: ai)cin >> i;
		if(k == 0){
			cout << 1 << endl;
			continue;
		}
		ll las = 32;
		ll ans = n + 1;
		for(ll i = 32; i >= 0; i--){
			if((k >> i) & 1){
				las = i;
				break;
			}
			vector<ll> lef, rig;
			for(ll j = 0; j < n; j++){
				ll x = (ai[j] >> i) & 1;
				if(x)lef.push_back(j);
				else rig.push_back(j);
			}
			for(ll j : lef){
				ll idx = upper_bound(rig.begin(), rig.end(), j) - rig.begin() - 1;
				if(idx >= 0){
					ans = min(ans, abs(rig[idx] - j) + 1);
				}
				idx = lower_bound(rig.begin(), rig.end(), j) - rig.begin();
				if(idx != rig.size()){
					ans = min(ans, abs(rig[idx] - j) + 1);
				}
			}
		}
		ans = min(ans, cal(ai, las, k));
		reverse(ai.begin(), ai.end());
		ans = min(ans, cal(ai, las, k));
		if(ans == n + 1)ans = -1;
		cout << ans << endl;
	}
	return 0;
}