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

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

Neapolis University Pafos

Привет, Codeforces!

Благодаря поддержке Neapolis University Pafos, продолжается серия образовательных раундов. Университет предлагает получение степени бакалавра в области компьютерных наук и искусственного интеллекта со стипендиями JetBrains. Получите передовые навыки в области искусственного интеллекта и машинного обучения, которые подготовят вас к востребованным техническим карьерам. Любопытно? Присоединяйтесь к прямой трансляции во вторник, 29 октября в 17:00 UTC, чтобы узнать о программе CSAI, ее учебном плане, структуре курсов, стипендиях, стажировках для студентов и практическом подходе к обучению.

Хотите получить больше опыта в программировании и математических соревнованиях?
JetBrains Youth Challenge возвращается в ноябре 2024 года!

Кто может участвовать?
Возраст 13–18 лет.
Все, кто в настоящее время обучается в средней школе.
Зарегистрируйтесь сейчас.

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

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

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

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

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

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

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

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

qp

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

I got a question, the penalty of time i.e. 10 minutes is the format of div. 3 and it is in this contest which is div. 2 so will the hacks have -ve points on unsuccessful attempts?

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

If I get minus again in this contest,I will leave CP.

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

I haven't lately been able to see any of the other users' submissions. Everything I see is "N/A" for source code, even for problems I have solved. Any solution to this very annoying issue? Thanks!

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

Today is my debut contest with Rainboy strategy , gonna start from $$$D$$$

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

Doing contest, problem B feels weird AF so imma skip it. Please correct me if it's skill issue.

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

$$$A$$$ is hard ._.

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

What the hell is this Problem B?

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

took 2 minutes for A and 2 hours for B

hardest B i've ever seen fr

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

how to solve E?

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

B?!!!! Why is n < 2000? Is it really n^2 for odd n? How to solve B?

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

please don't write problems like B again

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

What is the solution for B?

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

    You can binary search for each k from low = 0 and high. = (arr[n-1] — arr[0])

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

      why return cnt >= n/2;

      how you got this idea?

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

        I will try to explain it here, let me know if you get it or not.

        cnt is the count of pairs, number of pairs should be n/2, as 2 elements make up a pair. Also imp thing is we only have to check diff between conseq elements as least diff of any j with current i will be when j = i + 1 as array is increasing. eg: if n = 6. there should be 3 pairs. if n = 7, there should be 3 pairs and the remaining 1 we can match by adding our available "atmost one addition case".

        n is even : Lets say a = {1, 5, 8, 10, 13, 14} and k = 3 here 1 and 14 would not get a pair (as (5-1) = 4 > k & 14 doesn't have a pair to match with), whereas (5, 8) and (10, 13) can make up pair. So cnt = 2. As we can only add atmost 1 number, we can't make pair for both 1 and 14. So k = 3 is not feasible. if cnt was 3 (= n/2) then that means all the numbers have pairs. So its feasible.

        n is odd : Lets say a = {1, 5, 8, 10, 13} and k = 3 here 1 would not get a pair (as 5-1 = 4 > k), whereas (5, 8) and (10, 13) can make up pair. So cnt = 2 (= n/2). As we can only add atmost 1 number, we can make a pair for 1 by adding 0. So k = 3 is feasible.

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

    observe if we have n==even , then we cant take the extra element as that can't be compensated by any other element while making pairs so just find the max difference b/w consecutive elements, if n==odd , we have the choice to leave one element and find an extra new one for it, we can do this for each element and store the max diff to the right of it and to the max diff b/w consecutive elements to the left of it and take the max of both the overall answer for this case would be minimum of all such cases

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

c's gonna make me cry when i see the case im failing on

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

please don't write problems like B again

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

after the contest, i felt like it is somehow harder than the last div1+2

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

Many low-rated people solved D in the last 15 minutes, I don't know if it's my skill issue but I don't think it is an easy problem. So please skip those who cheated.

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

couldn't solve any thing I'm mad but at least the problems are not guessing problem

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

I mean I like prefix sums, but prefix sums of prefix sums of prefix sums is too much man.

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

AC D at 1:59 :)

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

I spent close to 38 minutes for problem A and got one wrong on B just in hurry of choices Struggle is real kn geometry problems

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

today D feels like a buffed version of 2009F - Firefly's Queries.

Which I regret haven't upsolve the problem yet...

But idk maybe I'd stuck on this anyway.

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

E: Build a bipartite graph with n vertexs on the left and 60 vertexs on the right. For each 1<=i<=n and 0<=j<60, we add an edge if a[i] has j-th bit set on. For any subset of left nodes, the score is (number of chosen left vertexs )-(number of right vertexs with edge connected to chosen left vertexs ) = (number of chosen left vertexs )+(number of right vertexs without connection to chosen left vertexs )-60, then the answer is (Size of maximum independent set)-60. By the Konig theorem: In any bipartite graph, the size of maximum matching is same as minimum vertex corver, and (size of minimum vertex corver)+(size of maximum independent set)=n+60, we can calculate answer by any maximum matching algorithm.

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

If i've submitted twice of one problem which one will be counted? If first one is hacked then second one counted?

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

There is nothing educational about B.

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

B reminds me with this problem

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

im really confused why my binary search submission failed on B, and then my brute force one passed. obviously n is 2000, so i kinda knew it was brute force, but i didnt come up with any counter test case for my binary search one, can someone give a counter example?

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

In problem E, what does "set bit" mean ?

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

https://mirror.codeforces.com/contest/2026/submission/288585044

can someone help why this is wrong?

Greedy solution. Logic is that I store all the i where s[i] == 1 in a greater int set. ans = (n*(n+1))/2

I iterate over them{ count = 0; I have 2 variables l and r, I iterate over l from n->0. if I find s[l] == 0, then count++; if I find s[l] == 1 then I check on count, if it is 0 then I move more left.

When my 0s are exhausted, I move to r and only check the 1s from 1->n, if there is a 1 corresponding the I make count++, if there isnt then I break,

if there is a count then I reduce the answer by the indes of the one in the starting loop}

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

    The algorithm I used:

    1. Greedily scan from right to left
    2. If s[i] = 1, pair it with rightmost '0' (pos<i)
    3. Else pair it with the leftmost '1'

    In 2,3 just store the i, in these cases only, you will be saving money.

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

    If s[i] = 0, the value $$$i + 1$$$ would be added to the cost no-matter what.

    Go from right to left. The idea is to greedily exhaust the rightmost $$$1's$$$ with the first encountered $$$0's$$$ from right to left. If we exhaust in pairs, we will be able to remove as many $$$1's$$$ as possible.

    Use a std::deque to store the cost generated by $$$1's$$$. Larger values are stored in the front.

    if s[i] == 0,
    if !dq.empty() do pop.front(); if it is empty, we can pair it with the already exhausted $$$1's$$$.
    do cost += i + 1

    if s[i] == 1 do dq.push_back(i + 1). Finally when the dq contains $$$1's$$$, we can greedily exhaust the largest(front) and smallest(back) values.

    https://mirror.codeforces.com/contest/2026/submission/288593783

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

PD I know prefix sum. But just too heavy implemention... run out of time. :(

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

Do I understand right that problem F is just:

Code persistent queue on 6 stacks, in stacks we store knapsacks, so when answering the query we can just take left and right knapsacks and bruteforce the sum on each edge

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

Is large number in cpp necessary to solve problem D?

Is there a great large number template in cpp? emmmmm

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

how to solve C?

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

wrong A why cant long long ? https://mirror.codeforces.com/contest/2026/submission/288534007

0 0 68724335200 68724335200 0 68724335200 68724335200 0 0 0 68724335200 68724335200 0 68724335200 68724335200 0 0 0 68724335200 68724335200 0 68724335200 68724335200 0 0 0 68724335200 68724335200 0 68724335200 68724335200 0

wrong output format Expected int32, but "68724335200" found (test case 1)

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

Can anyone try to hack this submission? I think greedy cannot pass this problem.

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

In these contests, is wrong answer on Test 1, considered as a penalty ?

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

Either I am getting dumb day after day, or A,B,C are actually getting difficult contest after contest.

Yesterday was Div (1 + 2) contest.

Today it is simply Div-2 contest.

I felt like today's ABC were more difficult, than Yesterday's ABC.

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

A had a really nice hint for the idea that AB, CD are diagonals of a square with side min(x,y) i.e. K<=1414 , hinting the appearance of root of 2

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

Problem E seems familiar

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

Could anyone please explain how to do B? I used binary search, but it didn't work.

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

Miss chance to become master AGAIN by declaring $$$a_i$$$ of Problem E as int, not long long.

Note: shifting more than bit width is an undefined behavior, so I get WA1, not WA2 or WA3, which is confusing to me.

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

D is very reminiscent of Mosaic from this year's IOI.

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

Can anyone please explain why my solution fails:

Method: For even n, directly calculate the max distance between all pairs (a[0],a[1]), (a[2], a[3]).....

For odd n, calculate min(max(((a[0],a[1]), (a[2], a[3]).....), ((a[1],a[2]),(a[3],a[4]).....))).

Submission

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

Spent a lot of time thinking about E after coming up with the obvious Maximum Matching algorithm, not able to believe its actually the intended solution.

While not having a template for it cost me today's E, I am really surprised Maximum Matching was allowed to appear in E, especially when the idea that each bit should have atleast one unique entry is quite simple.

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

    I agree that it is too much for E. But it seems to me that we have no right to complain, since this is Educ and in fact it is intended for this: you know an algorithm — 3 minutes will be enough for you, if you don't know — you are cooked for the next two hours.

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

"Euclidean or Manhattan" missing from "A"s statement.

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

Are there any ways to solve problem E with dp? I tried to solve it with dp but get WA.

Let dp[i][j] represent the value of mask such that the number of 1-bits in mask is minimized when constructing a subsequence of length j with i as the last element of the sequence.

I think we can combine with some greedy tactics, such as save more than one mask for each dp[i][j] at a time.

Sorry for my bad English.

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

Using random to solve E: (This is gonna WA on test 2) (OMG, it's running on test 10!) (OMG, it's running on test 20!) (OMG! It ACCEPTED!!!) (I'm going to submit a lot of them to ensure I can pass main test) (passed 6/27) (ALL 6 AC submissions are hacked, rank 103->511 QAQ)

So is there a way to hack these submissions at a high possibility? Or it was just because I was to silly when randomizing? Can these submissions be hacked? 288611596 288611196

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

for problem B this case

2
1 3

why the answer is 2 and not 1

if k=1 then we paint 1 and 2 and then we can easily paint 2 and 3 ??????????? why I'm reading the statement wrong every time ????

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

Seems that problem F only have operation 3 in the sample. See here

code copied from jiangly's code and add one assertion on operation 3. Only have 96 tests during the contest while the verdict is RE on 97.

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

    My bad :( We only discovered that during the contest. Somehow all incorrect solutions we had were incorrect even on that set of data and all correct were still correct after the generators got fixed. Luckily, not a lot of people got affected by the incomplete tests.

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

could someone provide counter example for this submission , im getting WA on test 5, and the solution seems kinda silly but it runs in O(60*n^2) in worst case scenario, and it seems correct to me. basically what i do is for every element i, lets call it valid, if for every bit that is set in in a[i], it has atleast 1 valid neighbour. first we assume all indices are valid, and then we check if there is an element that isn't and if there is such an element we delete it, and also since it may have made some other indices valid, but now doesnt anymore, we have to repeat this until no changes occur. this runs in O(60*n^2) in the worst case where we delete 1 element per iteration, and every element will be deleted, so its fast enough. but its getting WA on test 5 and i cant seem to find a simple counterexample.

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

Educational contest educated me that I know nothing. Nothing: No, you don't know me. Me: He knows me. He: Who, are you? Who: No, I am not "?". Not: No, your not Not. No: I know.

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

C was easier than B, also A was weird. not a balanced contest tbh,

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

The pretest of B is quite weak.I solved 5 problems, but I hacked my own B successfully.

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

What the hell was that B question ?? After several incorrect submissions, I came to a conclusion that its a BS + DP problem.

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

I can't figure out why this code got WA on D. How mysterious.

#include <bits/stdc++.h>
#define MAXN 300005
using namespace std;
typedef long long llong;
llong n,q,L,R;
llong a[MAXN],presum[MAXN],sumsum[MAXN],press[MAXN],ppsum[MAXN];
llong find_pos(llong p) {
	llong l=1,r=n+1;
	while(r!=l+1) {
		llong mid=(l+r)/2;
		if (n*(n+1)/2-(mid-1)*mid/2>=p) l=mid;
		else r=mid;
	}
	return l;
}
llong query(llong p) {
	if (p==0) return 0;
	llong len=find_pos(p),order=n-len+1;
	llong starting=n*(n+1)/2-len*(len+1)/2+1;
	llong minus=presum[order-1];
	llong ans=ppsum[p-starting+order]-ppsum[order-1]-minus*(p-starting+1)+press[order-1];
	return ans;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for (llong i=1;i<=n;i++) {
		cin>>a[i];
		presum[i]=presum[i-1]+a[i];
		ppsum[i]=ppsum[i-1]+presum[i];
		sumsum[1]+=presum[i];
	}
	press[1]=sumsum[1];
	for (llong i=2;i<=n;i++) {
		sumsum[i]=sumsum[i-1]-(i-1)*(n-i+2);
		press[i]=press[i-1]+sumsum[i];
	}
	cin>>q;
	for (llong i=1;i<=q;i++) {
		cin>>L>>R;
		cout<<query(R)-query(L-1)<<'\n';
	}
	return 0;
}
»
18 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Hard A. However, 3k people solve it in 5 mins. I DO think lots of cheaters in A. D is good. I need to practice more prefix sums, to find indexes faster.

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

Awesome contest!I am rank 3 and will become IM!

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

Why unrated?

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

MinusForces

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

problem D makes me feel like I'm not participating in CP …… All of the difficulty is to write the code. Too little about algorithm and too much about coding. Well, maybe it can help us improve our coding ability ……

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

    problem E is also not good. If you know Maximum Weight Closed Subgraph you can solve it quickly, but if you don't know that you are hardly solve it.

    I think Div .2 D and E should have good ideas without too hard code or too hard algorithm.

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

      Isnt the point of Educational Rounds to teach these topics to a wider range of participants?

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

      By your logic, Problem F is also formulaic for those who knows tree division — it is just to decompose the knapsack dp onto a tree. However, in my opinion an edu round is to be formulaic as it aims to educate.

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

        In my opinion, Edu round is more important to teach participants how to solve problem rather than a specific algorithm. In most contests like ICPC, only learned algorithms is not enough, it's more important to know when to use it and how to use it.

        It is acceptable to set problems like E or F. But I think problems which have more thinking instead of hard hard code or hard algorithm are better in a 2 hour edu round.

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

sbsbsbsbsbsbsb

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

Auto comment: topic has been updated by awoo (previous revision, new revision, compare).

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

Why can't I earn points in the last two games?