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

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

Neapolis University Pafos

Привет, Codeforces!

Благодаря поддержке Neapolis University Pafos, продолжается серия образовательных раундов.

В 28.04.2025 17:35 (Московское время) состоится Educational Codeforces Round 178 (Rated for Div. 2).

Этот раунд будет рейтинговым для участников с рейтингом менее 2100. Соревнование будет проводиться по немного расширенным правилам ICPC. Штраф за каждую неверную посылку до посылки, являющейся полным решением, равен 10 минутам. После окончания раунда будет период времени длительностью в 12 часов, в течение которого вы можете попробовать взломать абсолютно любое решение (в том числе свое). Причем исходный код будет предоставлен не только для чтения, но и для копирования.

Вам будет предложено 6 или 7 задач на 2 часа. Мы надеемся, что вам они покажутся интересными.

Задачи вместе со мной придумывали и готовили Адилбек adedalic Далабаев, Михаил awoo Пикляев, Максим Neon Мещеряков и Александр fcspartakm Фролов. Мы бы хотели выразить свою благодарность Алексею ashmelev Шмелеву за тестирование задач и важные замечания по ним. Также большое спасибо Михаилу MikeMirzayanov Мирзаянову за системы Polygon и Codeforces.

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

Удачи в раунде! Успешных решений!

Наши друзья из Neapolis University Pafos также хотят передать вам сообщение:

Продолжается прием на бакалавриат по программе "Компьютерные науки и искусственный интеллект" в Neapolis University Pafos!

JetBrains Foundation поддерживает эту программу бакалавриата и предоставляет 20 полных стипендий для самых талантливых абитуриентов. Стипендия покрывает стоимость обучения, проживание, медицинскую страховку, визовые сборы и карманные деньги (300 евро в месяц).

Узнать больше о программе →

Отличные новости! Если вы не успели подать заявку в первом потоке — у вас ещё есть возможность присоединиться ко второму! Подайте документы, пройдите вступительное тестирование и собеседование — и вы сможете получить полную стипендию.

  • Срок подачи заявок – 12 июня 2025
  • Вступительный тест – 15 июня 2025 (это последний вступительный тест 2025 года!)

Кроме того, для студентов, уже обучающихся по направлению «Компьютерные науки», доступны 2 полностью финансируемые стипендии для перевода на второй курс программы.

Если у вас остались вопросы, обращайтесь в Telegram-чат или пишите нам на почту — [email protected]! Мы всегда готовы помочь!

upd: Теперь включена возможность регистрации вне конкурса. Приносим извинения за доставленные неудобства.

upd2: Разбор опубликован.

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

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

hope for a good contest)

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

I wish we could have a

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

Hope to have such a DASHBOARD that will make me forget the last round..!

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

As a participant, I hope to solve three questions tomorrow.

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

As a participant I would Hope to see no newbie in top 10

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

As a participant I hope to see no newbies with Grandmaster skills

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

As a participant, Hope that This contest will be good for all...

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

Hope to get to orange

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

Hy everyone, i just started codeforces from the last month. can someone review my profile and tell me wether i am doing ok or not. which parts i neeed to improve. Also, how can questions should i expect from this contest so that i can solve them ?

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

    Just keep solving the prolems in 800-1200 range atleast for one more month to build a solid foundation. Then move ahead. Your practice regime looks good. Just be at it..

  • »
    »
    18 месяцев назад, скрыть # ^ |
    ← Rev. 2  
    Проголосовать: нравится +12 Проголосовать: не нравится
    It's a good way to begin with basic algorithms. When my rating was below 1400, I started with partial sums and differences, greedy, binary search and some constructive problems and math problems. The algorithm which left me the greatest impression was double pointers because that was the very beginning of my experiences in Algorithm Contests. It shocked me a lot and made me feel the beauty of algorithms at that time. For me, I have better skill in mathematics than coding, so I always practice harder problems in stuffs like permutations, number theory, etc. Algorithms like DP, searching, data structures (For example: Binary Indexed Trees(BIT), Segment Trees, Disjoint Set Union(DSU)) are also fundamental. I learned them after I became Specialist, but I'm still not really skilled at them yet:C
    Also it's recommended to practice in contests. You can participate in every div4, div3, div2, div1+2 and edu if possible. Atcoder has a type of contests named ABC and begin at 20:00(UTC+8) every Saturday, which are very suitable for beginners. Sometimes you can do Virtual Participation in div3 and div4 rounds before. When your rating gets higher, it could be div2. Sometimes you might encounter a situation that you have the ability to solve some problems, but don't have enough time to pass in the contest. This time don't forget to make more trials after the contest, it will help a lot if you get Accepted.
    Different people might have various learning process from each other. Hope you will enjoy your time in Codeforces and become more skillful in the future!
»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I'm not getting the normal "out of competition" reason when registering for this contest. Is this a bug?

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

Positive delta pls

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

Those who participated in any of those rounds and decided to participate in this round too – then how can Codeforces stop them?

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

Why unrated participation is not there this time?

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

It is my first game in codeforces.I hope that I will pass at least 1 question.I don't know how hard the questions because I am a beginner of computer science.Good luck for me.

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

It looks like the opportunity for unrated registration for the round was accidentally turned off. We have turned it back on; you can now use unrated registration. Sorry for the inconvenience.

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

What's the difference in normal round and edu round?

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

Here I am, an old CP guy, trying his luck again into this! Need all of your luck please!

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

Here I am, an old CP guy, trying his luck again. Need all of your luck!

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

actually I noticed for first time that there is unrated registration option... is this available for div2 and other contests as well ?

I think this is a really useful feature and didn't know about it

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

Love this contest for:

  1. The clear declaration;

  2. Balanced problem difficulty distribution so that we perform better than we did in some unbalanced div2 based on the number of solved questions.

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

Speedforces strikes again

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

there are so many cheaters in this contest , idk if this could be handled or not but we should take a look at D E F G solvers

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

Div.3 Round :)

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

loved the round...truly an educational round(atleast for a newbie like me) learnt a lot from the problems:))

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

Is it a Div.3 ????

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

This is my first contest in codeforces, I'd say I've enjoyed it though i only solved 3 of them :) The problem C was interesting for me.

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

wtf is test 6 on E

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

How to solve E ?_?

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

    You can use a array of set to store the position of every char to check if a string lie as a subsequence or not in NlogN then two cases are possible:

    • the string t is not found as a subsequence in s straight away the answer is 0
    • if the string t is exhausted you will have the last position in s upto which the prefix substring is capable of giving t now we can try out all possible k characters one by and the raising the required pointer to that index, basically trying out all possible cases , we can optimise this with dp

    My submission link : submission link

    although I am not sure it will pass hacks or not cause the time consumption is really on edges

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

      it's not necessary to use a set. you can pre-process an array pos[N][26], pos[i][j] means the next position of a letter(j) starting from the current position i. so the time of binary search will be spared

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

        I had exactly done this but after looking other solution i do realize it does not make much diff if we use binary search or this approach as it will take 26*n time to precompute in this approach and it will take 10^5 * logn time for queries if done with other approach and for constraints of problems both are approx. same

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

The problem statements were both concise and brilliant. TFM!

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

https://www.youtube.com/live/tf5RnMbFyRk?si=eFgYAEuREH-SP9cq

Youtube channel: @learningunique codeforces handle: aayushrathour34 doing livestream during contest

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

jump in diff from e to fg was lowkey crazy xd well written ps though

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

codeforces $$$\times$$$

cheater forces, gap forces $$$\sqrt{}$$$

I can confirm there are infinity cheaters solve DEFG fast

upd: Cheaters can get solution during the contest on https://www.youtube.com/results?search_query=Educational+Codeforces+Round+178+(Rated+for+Div.+2), it is ez to find it

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

Could someone help me with problem D? I have made an observation that the array is "ideal" if and only if all of the elements of the array are primes, and then I tried to run a binary search to find how many elements have got to be deleted, but it gave WA 2?

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

    you should binary search over amount of elements being deleted ( say k ) at each step of binary search, you check if deleting k smallest elements helps.

    to check, you should use the fact that any array with sum S and N elements. can converted to N first primes iff S >= sum of N first primes

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

      Can you show why it is not possible if sum of the array < sum of N primes?

      I got stuck at the thought of making the first N-1 elements as primes and whatever is left from the sum can "Maybe" be used to make the entire array satisfy the gcd condition. but i couldn't find a proof :(

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

        If the sum is not atleast the sum of primes, then all the elements can't be distinct primes , so some of the numbers have to share factor with some other , which violates the condition(two elements should have gcd =1) , so decrease the array size till you can satisfy sum of array >=sum of array.size() primes.

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

          yeah i figured that duplicate primes exist and then it violates the gcd condition, but is there a way to put composites that dosent violate the gcd condition?

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

            composites are 1 or more primes themselves used , so if you use composites ,it becomes worse as now you cant use the 1/+ primes used in one number in another number , meaning if a[i]=p*q say , then what we could have used p and q for 2 different numbers .

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

    Try to convert the largest element of array into smallest prime number, it will give you additional coins for future.

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

    so make an increasingly sorted array of the first n primes,and sort a decreasingly, then just find the first element where the prefix sum of the primes is larger than the prefix sum of a, those are all the elements that can stay, so the answer is n-(index of that element). no need for binary search

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

Beautiful problems. thank you!

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

What in the Speedforces' sake is this? I misread problem E from "adding to the right" as "adding from the right" and lost 1000 rankings.

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

Very nice problems, especially problems D & E. Thanks for preparing such contest! ^^

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

E: only if I can solve https://codeforces.me/contest/1925/problem/C in O(26 * log n) :sob:

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

One of my best contest yet, I was able to solve 5 questions in Div2 for the first time :)

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

kid named problem F

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

For problem E, I tried to implement a greedy approach using Binary search on the indices. Got TLE on Testcase 9 :(

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

    you can optimize your approach by precomputing the result using DP

    for each index $$$i$$$, what is the minimum number of allowed letters that I can add such that it won't be a beautiful string?

    precompute this using DP and your answer should work well

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

    Greedy works. you used binary search to find the string 't' last index right? now you can again use binary search to calculate number of operation required.

    come from last on string s, put all index to some list when all k character are visited. now binary search on that list.

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

    Same thing happened with me . I was able to figure out my error just after the contest :(

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

317640862 can someone explain me why 1e6 primes are not enough in problem D? (given n<=4.1e5)

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

div2 or div3???

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

Was the contest way easier than usual?

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

can someone please help, why doesn't my submission 317647877 work for C?

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

Missed E by 2 min. shit. It was easier than D.

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

When will submissions open?

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

I hope that system tests are strong enough

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

just look at number 6,7,8,9,10,11,12 in the div2 standing why they don't get banned????

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

expected ratings of b and c?

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

Speedforces type shit

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

A to E are easy for being a Div.2 problems and the whole contest (A-G) was leaked in YT. I wish CF find a solution for this unfair competition. However, the contest is below the average as a div2. I know some contestants will not like my opinion but see that your delta doesn't rate the contest (like getting +100 the contest is cool while getting -50 the contest is bad).

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

Please, Check my solution for D and tell what's wrong

vector<bool> seive(ll n){vector<bool>primes((n+1)/2,0);for(ll i=3;i<n;i+=2){if(primes[i/2]==false)for(ll j=i*i;j<n;j+=i*2){primes[j/2]=1;}}return primes;}
vector<bool>primes;
vll p;
void solve(){
    int n;
    cin>>n;
    vll arr(n);
    for0(i,n)
    cin>>arr[i];
    sort(arr.begin(),arr.end());
    vll left;
    int m = p.size();
    int j=0;
    ll coin=0;
    int i=0;
    for(;i<n;i++){ 
        coin += arr[i]-p[i];
    }
    for(i=n-1;i>=0&&coin<0;i--){
        coin-=(arr[i]-p[i]);
        coin+=arr[i]-2;
    }
    
    cout<<n-i-1<<endl;
}
int main(){
    fast_io();
    primes=  seive(1e6*7);
    p.pb(2);
    for(ll i=3;i<=1e6*7;i+=2){
        if(primes[i/2]==false)
        p.pb(i);
    }
    int T;
    cin>>T;
    
    while(T--)
    solve();
}
  • »
    »
    18 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится -8 Проголосовать: не нравится

    Hey Amigo I don't understand how you find prime numbers. :/ I use sieve of Eratosthenes; https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

    And that after deleting the numbers, only their sum is important. Its my code :

    #include <bits/stdc++.h>
    #define ll long long
    #define pb push_back
    #define all(x) x.begin(), x.end()
    #pragma GCC optimize ("O3")
    #pragma GCC optimize ("Ofast")
    using namespace std;
    const int N = 1e5 + 100;
    
    signed main(){
    	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    	int t;
    	cin >> t;
    	while(t--){
    
    		int cntb = 0, cnta = 0;
    		int n;
    		string s;
    		cin >> n;
    		cin >> s;
    		for(int i = 0; i < n; i++){
    			cntb += (s[i] == 'B');
    			cnta += (s[i] == 'A');
    		}
    		s = '.' + s;
    		if(s[n] == 'B'){
    			if(cntb > 1)
    				cout << "Bob" << endl;
    			else
    				cout << "Alice" << endl;
    		}
    		else if(s[1] == 'A' or s[n - 1] == 'A')
    			cout << "Alice" << endl;
    		else
    			cout << "Bob" << endl;
    		
    	}
    	return 0;
    }
    
    • »
      »
      »
      18 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится
      #include <bits/stdc++.h>
      #define ll long long
      #define pb push_back
      #define all(x) x.begin(), x.end()
      #pragma GCC optimize ("O3")
      #pragma GCC optimize ("Ofast")
      using namespace std;
      const int N = 1e7;
      
      bool cmp(int &a1, int &a2){
      	return a1 > a2;
      }
      bool mark[N];
      vector<ll> vec;
      
      signed main(){
      	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
      
      	for(int i = 2; i < N; i++){
      		if(mark[i] == 0){
      			if(vec.empty())
      				vec.pb(i);
      			else
      				vec.pb(i + vec.back());
      
      			for(int j = i; j < N; j += i)
      				mark[j] = 1;
      		}
      	}
      	int t;
      	cin >> t;
      	while(t--){
      		int n; 
      		cin >> n;
      		int a[n];
      		for(int i = 0; i < n; i++)
      			cin >> a[i];
      		
      		sort(a, a + n, cmp);
      		int k = n;
      		ll sum = 0;
      		for(int i = 0; i < n; i++){
      			sum += a[i];
      			if(sum >= vec[i])
      				k = n - i - 1;
      		}
      		cout << k << endl;
      		
      	}
      	return 0;
      }
      

      Sorry, I sent the wrong code :>

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

        My seive logic is correct I checked, but the problem was in my logic

        I increased my coins by decreasing the unwanted elements to 2 as in question it mentioned they should be atleast to 2 then I deleted them

        That's why I got extra score, it is not clearly mentioned in problem we can't do that I used a lil extra brain it's so funny

        My submission got accepted now thanks man

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

I like that div3

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

This is the simplest div2E I have ever seen, the last one so simple was 1978E, and it is recommended that the producers consider the difficulty gradient of the problems.

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

The system testing is stuck at 100% because a certain submission is stuck at running on test 1. You can filter submissions to check that.

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

Why does my submission (not only my) 317649033 to problem E fail on test 6?

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

how to solve E using the concept of lcs

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

speedforces

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

how to solve E

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

Today's contest was so easy a bunch of greys AK'd the contest.

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

what is the idea for E?

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

    from a particular position to append a new character it's always optimal to go to one particular index which creates a DAG structure so you can call it dp too

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

    The high level idea is this:

    For a single query T, let U be a prefix of S that contains T as a subsequence, and V be the corresponding suffix (i.e., S = UV). If there is no such U then T is not a subsequence of S at all and the answer is 0. Otherwise, the number of characters we need to add to T to make it not a subsequence of S is equal to the number of characters in the shortest string that is not a subsequence of V. Note that this number depends only on the length of the suffix, not on the specific contents of T.

    Let's call this number $$$extra(i)$$$, defined as “the number of characters in the shortest string that is not a subsequence of the suffix of S starting at 0-based index $$$i$$$”. Clearly the values of $$$extra(i)$$$ are nonincreasing as $$$i$$$ increases, since any string that is a subsequence of some suffix of S is also a subsequence of a longer suffix of S (note: lower $$$i$$$ means longer suffix).

    This implies that for any particular T, we only need to find the shortest suffix U.

    Define $$$next(i, c)$$$ as the least index $$$j ≥ i$$$ such that $$$S[j] = c$$$. We can precalculate this in $$$O(26×N)$$$ time.

    We can also calculate $$$extra(i)$$$ in $$$O(26×N)$$$ time using $$$next(i, c)$$$ (this is dynamic programming, technically).

    Now for a given T, we use $$$next(i, c)$$$ to find the shortest prefix U that contains T as a subsequence in $$$O(|T|)$$$ time by repeatedly finding the next character of T in S. When we've found U, we simply return $$$extra(|U|)$$$ as the answer.

    This solution takes $$$O(26×N)$$$ preprocessing time, and additionally time proportional to the sum of the lengths of the query strings T, which is bounded to $$$10^6$$$.

    This is the logic behind my submission 317615565.

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

How to do task C about card game, can somebody explain it please ?)

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

    Suppose Alice has a card that Bob doesn't have a counter. Then, Alice can keep playing that card until Bob gives all his cards. Hence, Alice will always be able to win. Only in the case when Alice do not have any card that Bob doesn't have a counter, Alice looses.

    To find counter of a card, for card 1 to N — 1, you can check if any card with greater label exist on opponent's hand and for card N you can check if card 1 exists on opponent's hand.

    This is the simplest way to solve the problem. It can further be optimized by making other observations but given the problem constraints this was sufficient.

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

    I had this idea:

    Every card beats card that is less with exceptions: 1 beats n

    So i made graph where for each card i store list of cards which beats it. After this for EVERY card that Alice have i'm checking if Bob have ANY card that beats it using graph earlier.

    You can check my submission: https://codeforces.me/contest/2104/submission/317613034

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

    I just enumerated the different cases:

    1. If Alice has 1 and N, then she can win by always playing N which beats every card Bob has.

    2. If Alice has 1 but not N, then there are two cases:

      1. if Bob only has N, then Alice wins by playing 1.
      2. otherwise, Alice loses, because Bob can play N every time except when Alice plays 1.
    3. If Alice has N but not 1, then:
      1. if Alice also has N-1 she will win by only playing N-1, which beats every card Bob has.
      2. otherwise, she will lose, because when Alice plays N Bob will play 1, and when Alice plays any other card, Bob will play N-1.
    4. Otherwise (Alice has neither 1 nor N), she loses because Bob can always play N which beats every single card Alice has. (This is the converse of case 1.)

    So Alice only wins in cases 1, 2a and 3a, which are easy to detect.

  • »
    »
    18 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится
    Your code here...
    import java.util.*;
    public class Main{
        public static void main(String[] args){
            Scanner s = new Scanner(System.in);
            int t = s.nextInt();
            StringBuilder res  = new StringBuilder();
            while(t-->0) {
                int n = s.nextInt();
                s.nextLine();
                String str = s.nextLine();
                char[] arr = str.toCharArray();
                if(n==2){
                    if(arr[0]=='A'){
                        res.append("Alice\n");
                        continue;
                    }
                    if(arr[0]=='B'){
                        res.append("Bob\n");
                        continue;
                    }
                }
                if(arr[0]==arr[n-1] && arr[0]=='B'){
                    res.append("Bob\n");
                    continue;
                }
                if(arr[0]==arr[n-1] && arr[0]=='A'){
                    res.append("Alice\n");
                    continue;
                }
                int count_A =0;
                int count_B =0;
                for(int i = 0;i<n;i++) {
                    if(arr[i]=='A'){
                        count_A++;
                    }else{
                        count_B++;
                    }
                }
                if(count_B==1&&n>2){
                    res.append("Alice\n");
                    continue;
                }
                if(count_A==1&&n>2){
                    res.append("Bob\n");
                    continue;
                }
                if(count_B>1&&arr[n-1]=='B'){
                    res.append("Bob\n");
                    continue;
                }
                if(count_A>1&&arr[n-1]=='A'&&arr[n-2]=='A'){
                    res.append("Alice\n");
                    continue;
                }else if(count_A>1&&arr[n-1]=='A'&&arr[n-2]=='B'){
                    res.append("Bob\n");
                }
            }
            System.out.println(res);
        }
    }
    
»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится -24 Проголосовать: не нравится

Hello Codeforces Team,

I acknowledge that previously my accounts had similarities due to me mistakenly using multiple accounts to check and submit codes, which I now understand was a serious mistake. I apologize for that.

Regarding the current incident (submission 317598688), I did not intentionally copy or leak my solution. I believe it is a misunderstanding.

I request you to reconsider the situation. I promise that from now on I will strictly follow all Codeforces rules and use only a single account.

Please give me one last chance.

Thank you for your consideration.

Handle: [ShantoRoy]

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

s

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

i dont understand why is my brute force solution getting wrong answer 317666531 can anyone help me out ? i also checked out other's solution it is the same if u test it mathematically

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

    You're making the mistake that one of the announcements explicitly addressed:

    “You are not allowed to increase/decrease elements and remove them afterwards. You have to remove the minimum number of elements to make the array beautiful, without applying the operations that change elements. They only define which array is beautiful and which is not.”

    So for a test case like:

    1
    6
    5 5 5 5 5 5
    

    Your solution will print 1 while the correct answer is 2. That's because you figure that $$$2 + 3 + 5 + 7 + 11 = 28 ≤ 6×5 - 2 = 28$$$ but in reality if you remove 1 element you only have $$$5×5 = 25$$$, so you must remove a second element and then $$$2 + 3 + 5 + 7 = 17 \lt 4×5 = 20$$$.

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

could any one please tell why this solution deosnt work for problem D Educational Codeforces Round 178??

My approach was to reduce every element of the array to '2' thus increase coins by a[i]-2.. so for each i from 1 to n I will do coins+=a[i]-2.

This is the maximum coins I can have..Now since the elements of the array are all'2' I will start assigning each element to a smallest available prime number starting from '2' for a[1]... Then I will check if I have enough coins left to transform a[2](which is '2' currently) to 3(next smallest prime number). If I have, then I reduce my coins by the curr available prime number-a[i]...

SO for each i I check if coins left >=required coins to transform the ith element to the next available prime number. If the ith element can not be made prime then we stop . And the number of elements which could not become prime number is the answer...

Please tell where I am wrong because I think my approach is right but its failing the second test case.....

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

can somebody hack my solution solution for problem e.

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

    Oops, sorry. I have succeeded. Didn't expect it myself

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

      Thanks brother

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

      Can you tell how hacking works, the articles on hacking are rather ambiguous.

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

        Hacking is, basically, coming up with some test which would give WA/TLE (basically any incorrect verdict) on someone's solution.

        There's two methods for uploading a test, which are: 1) upload the txt 2) upload the code which yields the output for testcase.

        The second option's program called generator. Here's the code which I submitted as generator.

        Generator's code

        To get some idea, what exactly is generated you can run this code locally and set N = 1e2, Q = 1e1.

        Your output also has to be correct regarding problem's constraints, i.e. n <= 1e6, Q <= 2e5 etc.. If not, then the problem checker would say something like "incorrect testcase"

        That's all I think you have to know to start hacking yourself. Good luck

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

      how about now is it still possible to hack

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

came back to cf after a long time felt good solving E

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

Who can tell me why my rank on the common standings is different from the friends standing?They're 65 and 99,and I'm sure the rating is base on the second one.Because in the last Div.2,they are 706 and 845 ,and the rank on the rating board is 845.

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

Do I get something wrong about D ? For the test cases $$$[2, 4]$$$ the answer shall be that we have to remove $$$1$$$ element (i.e. $$$4$$$ here) , But the AC code of the guy having rank $$$1$$$ gives $$$0$$$ as the output.

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

How to solve the problem F please? I guess there was too much different conditions that I didn't discuss about them completely.

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

Is the system testing done? Or yet to begin?

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

Forgot that the constraint for problem F was $$$n \le 10^9$$$ and solved it as if $$$n \le 10^{10^6}$$$. Maybe it’s a good idea to split it into an easy and a hard version :)

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

    Could you explain your idea?

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

      Consider which $$$x$$$ there does not exist any $$$y \lt x$$$ such that $$$S(x) = S(y)$$$. Excluding the obvious cases (for example, $$$y = 12349$$$ comes before $$$x = 32149$$$), $$$x$$$ is also not allowed to end with two or more $$$9$$$ (for example, for $$$x = 12399$$$, you can construct $$$y = 10293$$$), except for special cases such as $$$x = 1999\ldots9$$$, $$$x = 2999\ldots9$$$, ..., $$$x = 9999\ldots9$$$, and therefore, you also need to specifically consider numbers like $$$x = 90091$$$, because even though they meet the conditions above, $$$y = 19999$$$ paradoxically comes before it.

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

for problem G, i tried to implement the idea of square root decomposition on queries, and build a compressed graph for every block of queries, time complexity is $$$O(N\sqrt N)$$$ its giving tle at testcase 8.

Submission: 317677095

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

Check Pratap1617, he is kinda high for a pupil and his comments are kinda odd, if you know what i mean

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

Can someone give some hints for problem F?

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

    The number of distinct f(x)'s for x <= 10^9 — 2 is small enough to precompute them.

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

    I came to an example which feels close to solution: s(762)=s(672), so intuitively counting distinct strings means counting numbers where each less significant digit is >= more significant, except for least significant, which usually can be any. And need to figure out what to do with zeroes and tailing 9's s(3799)=s(3077), or s(3099)=s(3090).

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

Hi can someone help me figure out why my solution for E TLE for system tests and how I can improve it? If Im not wrong, it's already linear complexity with respect to (n + t).

317634919

Thank you in advance!

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

did not get the rating yet

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

When are the ratings gonna update [ : ( ] ??

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

This is a humble suggestion. Correct me if I'm wrong.

It is better to refrain from mentioning "This round is based some some X Olympiad". Let's say there were some Y people who participated in X, instead of informing them this disclaimer is helping at least 10Y people cheat. BledDest

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

I couldn't get what the fourth question was asking for , how did some people solves it in 19 mins !! , damn too good to look true and that too with 100+ lines of codes with names of variables as anime characters , damn !!

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

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

When is the editorial coming out??

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

solve problem F ạ

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

what is the intuition behinf E?

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

    you should find first occurrence of string t in s as subsequence. if there is no occurrence, then answer is zero if there is subsequence ending at index i. you should find the minimum length string that is not subsequence of s[i+1..n]. which is possible to find using dfs & memoization ( dp )

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

Since when did you have to solve 4 "FOUR". Since when did you have to solve 4 DIV 2 Problems. YOU HEARD ME RIGHT, 4 DIV 2 problems to become GREEN.

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

when will the editorial come out?i can't wait to know how to solve the F properly.

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

[Your text to link here...](https://blog.csdn.net/qaqwqaqwq/article/details/123587336) Dear administrator, I sincerely hope you can revoke the cheating penalty imposed on me. Problem 2104D significantly coincides with solutions hangogogo/317624815 and KrAuAg/317633096. I suspect this is because we might have used the same website template. I found the Euler sieve template in the CSDN community, specifically from the website https://blog.csdn.net/qaqwqaqwq/article/details/123587336. I don't know the user KrAuAg. I think the similarity between his code and mine is probably due to the fact that we found the same template on the same website. I'm truly sorry for the trouble this has caused. I deeply apologize for any inconvenience or misunderstanding this situation might have brought to you and the platform. I really respect the rules and regulations here and always strive to abide by them. Thank you very much for your time and understanding. Looking forward to your kind consideration. Best regards, for hangogogogo