atcoder_official's blog

By atcoder_official, history, 6 months ago, In English

We will hold AtCoder Beginner Contest 428.

We are looking forward to your participation!

  • Vote: I like it
  • -33
  • Vote: I do not like it

»
6 months ago, hide # |
Rev. 2  
Vote: I like it -10 Vote: I do not like it

Is this new judging system an update to the judge machine’s configuration, or does it simply add support for more programming languages? If they’ve actually changed the judge machine, maybe programs could run a bit faster? (I have a bit of a TLE phobia…)

»
6 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

No C++ 17 or 20 is wild

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

language brainfuck is among availible languages, wtf

  • »
    »
    6 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    ++++++++++[>++++++++++<-]>--.++++++++++++++++.-----------------.++++++++.+++++.--------.+++++++++++++++.------------------.++++++++.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Why 30min later?

»
6 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Strange start time.

»
6 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Did you update the contest start time?

»
6 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Is the contest delayed by 30min? Technical issues of the new judge?

upd:according to contest page it is delayed and new judges won't be used

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

It seems to be slower and slower for us to visit AtCoder... Even submitting a problem takes a few minutes :(

»
6 months ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

Is it rated?

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hope it will be high quality.

»
6 months ago, hide # |
Rev. 2  
Vote: I like it -10 Vote: I do not like it

why did E<<<D???

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

The comparision of tuple in E gives TLE under correct time complexity.

»
6 months ago, hide # |
 
Vote: I like it +16 Vote: I do not like it

Don't know why E was even included in this contest. D >>> E imo.

  • »
    »
    6 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +1 Vote: I do not like it

    I found E harder than D, it's a matter of taste. One could easily take a long to code approach in E and spend more time solving E than D even if the idea is conceptually easier.

»
6 months ago, hide # |
 
Vote: I like it +15 Vote: I do not like it

E is such a classic problem.Bad E.

»
6 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

(The favs only)

This is too bad.How the difficulty gap between D,E and F,G so big?

And E is too classic that it is a shit here.

Though I spent too much time on D,I think it's a good problem here.

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I agree with you. I think D is good, but E is rubbish(it's too classical and boring). What's more, the difficulty gap between E and F is too big.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
q=int(input())
res=[0]*q
stk1=[]
stk2=[]
for _ in range(q):
    query=input()
    if len(query)==1:
        if len(stk1)==1:
            stk1.pop()
            stk2.pop()
        else:
            prev=res[len(stk1)-2]
            cur=res[len(stk1)-1]
            stk1.pop()
            if cur>prev:
                stk2.pop()
            else:
                stk2.append(stk1[-1])
        if len(stk2)==0:
            print("Yes")
        else:
            print("No")
    else:
        stk1.append(query[-1])
        if query[-1]=="(":
            stk2.append("(")
        else:
            if stk2 and stk2[-1]=="(":
                stk2.pop()
            elif len(stk2)==0:
                stk2.append(")")
        res[len(stk1)-1]=len(stk2)
        if len(stk2)==0:
            print("Yes")
        else:
            print("No") 

What is wrong with my code for c

»
6 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

i think E > D :(

E solution is that take the diameter of the tree and do the bfs statistics to the dist of these two nodes.

vector<vector<int> > g;

vector<int> bfs(int s, int n)
{
    vector<int> dist(n+1, -1);
    queue<int> q;
    dist[s]=0;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front(); q.pop();
        for(int v : g[u])
        {
            if(dist[v]==-1)
            {
                dist[v] = dist[u] + 1;
                q.push(v);
            }
        }
    }
    return dist;
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	g.resize(n+1);
	for(int i=0; i<n-1; i++)
	{
		int u,v; cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	vector<int> d=bfs(1,n);
	int a=1;
	for(int i=1; i<=n; i++)
		if(d[i]>d[a] || (d[i]==d[a] && i>a))a=i;
	vector<int> da=bfs(a,n);
	int b=a;
	for(int i=1; i<=n; i++)
		if(da[i]>da[b] || (da[i]==da[b] && i>b))b=i;
	int maxn=max(a,b);
	vector<int> db=bfs(b,n);
	for(int i=1; i<=n; i++)
	{
		if(da[i]>db[i])cout << a << endl;
		else if(da[i]<db[i])cout << b << endl;
		else cout << maxn << endl;
	}	

	return 0;
}

But question D seems to be able to be written using binary search. Please give me some advice.

»
6 months ago, hide # |
 
Vote: I like it +15 Vote: I do not like it

Wow! Coder ME competed in Atcoder Beginner Contest 427&428 and gained -97 rating points! Share it!

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Rubbish Round

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

swap(D,E) plz

I think D>>>E.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

another speedcoder?? btw is F an ad-hoc? I simply didn't understand how the official editorial works

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Could the new judging system be opened for testing before the next competition starts? I don't want to face a completely new and unfamiliar system when I get to the ABC contest.

By the way, long live chez scheme!

»
6 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

My Java code strangely TLE and has an O(n) complexity. I tested it locally, timing the read from n to the output, and it only took 1300+ms. I can't figure out why it times out. I've never encountered such a Java timeout before. Does this mean Java won't be able to use DFS for 5e5 data in the future? Here's the submission link. I think it's due to the OJ system changes. Could atcoder officials please check it out?

https://atcoder.jp/contests/abc428/submissions/70268852

  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I haven't inspected your code sry, but FYI AtCoder has not changed their system for this contest (they planned but then rolled back due to a technical issue).

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Well, there must be something wrong with my code. I found that Java's DFS is 5 times slower than BFS, while C++ has no such difference.

»
6 months ago, hide # |
Rev. 2  
Vote: I like it -13 Vote: I do not like it

swap(D,E) please

D is terrible for me and I got rating-9 at last

E is too simple for this place.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How to approach problem C can anyone please help

  • »
    »
    6 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it
    In order to the answer the queries on the fly, we can keep track of 2 things
    1. Invalid prefix count : Number of prefixes where count(close) > count(open)
    2. Sum : count(open) - count(close)
    
    Now, we only have 2 cases to:
    
    case 1 : If Invalid prefix count is not zero, it means that there are some closing brackets that do not have any  corresponding opening brackets to pair with. Hence such a string can never be 'good' , unless such closing brackets are not removed. Eg : () | ) | (())
    
    case 2 : Invalid prefix count is zero (This means every closing bracket can be paired with an opening bracket. But is the vice-versa true ? (may or may not be) Because this does not sure that all opening brackets have corresponding closing brackets). We can ensure this using sum.
    i,e If sum is zero, then count(open) = count(close) and since no invalid prefixes, we can say this is 'good'
    
    
    
    Implementation
»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

my approach for D (This could help to understand better)

1 <= x <= d
F(c , c + x) => to_string(c) + to_string((c + x))
             => fixed prefix + varying suffix

and this suffix varies from : [c + 1 , c + d]

Initial thoughts calculate : find L , R:
    L = F(c + minSuffix)
    R = F(c + maxSuffix)

    ans = count(0....R) - count(0....L-1)

But this wont work ... why ?

say, c = 4 and d = 80
     suffix varies : [c + 1 , c + d]
                   : [5 , 84]

    L = "4" + "5" = 45
    R = "4" + "84" = 484

    when we use count(0....N), it consides all numbers in [0....N]
    which includes perfect squares with prefix other then 'c' => (81 , 100 , ...)


Solution!! : Break the suffix range into blocks

something like this,
[1 , 9] [10 , 99] , [100 , 999] , ....

Once again say, c = 4 and d = 80

L = "4" + "1" = 41
R = "4" + "9" = 49

L = "4" + "10" = 410
R = "4" + "99" = 499 -> greater than (maxR:484), so bound to maximum
               = 484

ans = [count(0...49) - count(0...41-1)] + [count(0...484) - count(0...410-1)]


Implementation
»
6 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

Could someone call me what's wrong with my code in problem F QAQ. I found that when migrating operations 1 and 2, there are actually intervals smaller than v that may move, so I tried using a segtree to solve this problem. At the same time, the line segment tree can also be used to split operation 3. But I successfully passed the sample and 10 points, but still had 6 WA points QAQ. Here is my code, because I am not very familiar with it. The lazy markers are relw_ay and rel_num, and lazy_ay and lazy_num correspond to whether the interval is offset to the left or right and the corresponding offset position. (I am a Chinese, please forgive me for not reading correctly. qwq)

#include <iostream>
#include <cstdio>
#include <cstring> 
#include <algorithm>

using namespace std;
const int N = 200010;
typedef pair<int, int> PII;

int n, q;
int w[N]; 

struct STree
{
	int l, r;
	int num;
	int rel_way = 0, rel_num = -1; 
	int lazy_way = -1, lazy_num = 0; 
} stree[N << 2];

void pushdown(int plc)
{
	int way = stree[plc].rel_way, lz = stree[plc].rel_num;
	if (way == 0 || (stree[plc].l == stree[plc].r))
	{
		stree[plc].rel_way = 0;
		stree[plc].rel_num = -1;
		return ;
	}
	stree[plc << 1].rel_way = way;
	stree[plc << 1].rel_num = lz;
	stree[plc << 1].lazy_way = way;
	stree[plc << 1].lazy_num = lz;
	
	stree[plc << 1 | 1].rel_way = way;
	stree[plc << 1 | 1].rel_num = lz;
	stree[plc << 1 | 1].lazy_way = way;
	stree[plc << 1 | 1].lazy_num = lz;
	
	stree[plc].rel_way = 0;
	stree[plc].rel_num = -1;
}

void init(int l, int r, int plc)
{
	stree[plc].l = l, stree[plc].r = r;
	if (l == r)
	{
		stree[plc].num = w[l];
		return ;
	} 
	int mid = (l + r) >> 1;
	init(l, mid, plc << 1);
	init(mid + 1, r, plc << 1 | 1);
	stree[plc].num = max(stree[plc << 1].num, stree[plc << 1 | 1].num);
}

PII query(int pos, int plc)
{
	if (stree[plc].r < pos || stree[plc].l > pos) return {-1, -1};
	if (stree[plc].l == pos && stree[plc].r == pos)
	{
		if (stree[plc].lazy_way == -1)
		{
			return {stree[plc].lazy_num, stree[plc].lazy_num + stree[plc].num};
		}
		else
		{
			return {stree[plc].lazy_num - stree[plc].num, stree[plc].lazy_num};
		}
	}
	pushdown(plc);
	PII res = {0, 0};
	res = max(res, query(pos, plc << 1));
	res = max(res, query(pos, plc << 1 | 1));
	return res;
}

void update(int l, int r, int lz_way, int lz_num, int plc)
{
	if (stree[plc].r < l || stree[plc].l > r) return ;
	if (stree[plc].l >= l && stree[plc].r <= r)
	{
		stree[plc].rel_way = lz_way;
		stree[plc].rel_num = lz_num;
		stree[plc].lazy_way = lz_way;
		stree[plc].lazy_num = lz_num;
		return ;
	}
	pushdown(plc);
	int mid = (stree[plc].l + stree[plc].r) >> 1;
	if (mid >= l) update(l, r, lz_way, lz_num, plc << 1);
	if (mid < r) update(l, r, lz_way, lz_num, plc << 1 | 1);
}

int query_insert(int pos, int plc)
{
	if (stree[plc].l == stree[plc].r) return stree[plc].l;
	pushdown(plc);
	int lz_way = stree[plc << 1].lazy_way, lz_num = stree[plc << 1].lazy_num, nm = stree[plc << 1].num;
	if (lz_way == -1)
	{
		if (lz_num <= pos && lz_num + nm > pos)
		{
			return query_insert(pos, plc << 1);
		}
	}
	if (lz_way == 1)
	{
		if (lz_num > pos && lz_num - nm <= pos)
		{
			return query_insert(pos, plc << 1);
		}
	}
	return query_insert(pos, plc << 1 | 1);
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++ )
	{
		scanf("%d", &w[i]);
	}
	init(1, n, 1);
	
	scanf("%d", &q);
	for (int i = 0; i < q; i ++ )
	{
		int op, v;
		scanf("%d%d", &op, &v);
		if (op == 1)
		{
			if (v == 1) continue;
			PII mov = query(v, 1);
			update(1, v - 1, -1, mov.first, 1);
		}
		else if (op == 2)
		{
			if (v == 1) continue;
			PII mov = query(v, 1);
			update(1, v - 1, 1, mov.second, 1);
		}
		else
		{
			printf("%d\n", n - query_insert(v, 1) + 1);
		}
	}
	
	return 0;
}
  • »
    »
    6 months ago, hide # ^ |
     
    Vote: I like it -8 Vote: I do not like it

    ok,I konw, for query 3 ,x is possible to be larger than Wn ,I didn't consider this QAQ, it is a bit stupid (). if someone need ,here is my last AC code

    #include <iostream>
    #include <cstdio>
    #include <cstring> 
    #include <algorithm>
    
    using namespace std;
    const int N = 200010;
    typedef pair<int, int> PII;
    
    int n, q;
    int w[N]; 
    
    struct STree
    {
    	int l, r;
    	int num;
    	int rel_way = 0, rel_num = -1; 
    	int lazy_way = -1, lazy_num = 0; 
    } stree[N << 2];
    
    void pushdown(int plc)
    {
    	int way = stree[plc].rel_way, lz = stree[plc].rel_num;
    	if (way == 0 || (stree[plc].l == stree[plc].r))
    	{
    		stree[plc].rel_way = 0;
    		stree[plc].rel_num = -1;
    		return ;
    	}
    	stree[plc << 1].rel_way = way;
    	stree[plc << 1].rel_num = lz;
    	stree[plc << 1].lazy_way = way;
    	stree[plc << 1].lazy_num = lz;
    	
    	stree[plc << 1 | 1].rel_way = way;
    	stree[plc << 1 | 1].rel_num = lz;
    	stree[plc << 1 | 1].lazy_way = way;
    	stree[plc << 1 | 1].lazy_num = lz;
    	
    	stree[plc].rel_way = 0;
    	stree[plc].rel_num = -1;
    }
    
    void init(int l, int r, int plc)
    {
    	stree[plc].l = l, stree[plc].r = r;
    	if (l == r)
    	{
    		stree[plc].num = w[l];
    		return ;
    	} 
    	int mid = (l + r) >> 1;
    	init(l, mid, plc << 1);
    	init(mid + 1, r, plc << 1 | 1);
    	stree[plc].num = max(stree[plc << 1].num, stree[plc << 1 | 1].num);
    }
    
    PII query(int pos, int plc)
    {
    	if (stree[plc].r < pos || stree[plc].l > pos) return {-1, -1};
    	if (stree[plc].l == pos && stree[plc].r == pos)
    	{
    		if (stree[plc].lazy_way == -1)
    		{
    			return {stree[plc].lazy_num, stree[plc].lazy_num + stree[plc].num};
    		}
    		else
    		{
    			return {stree[plc].lazy_num - stree[plc].num, stree[plc].lazy_num};
    		}
    	}
    	pushdown(plc);
    	PII res = {0, 0};
    	res = max(res, query(pos, plc << 1));
    	res = max(res, query(pos, plc << 1 | 1));
    	return res;
    }
    
    void update(int l, int r, int lz_way, int lz_num, int plc)
    {
    	if (stree[plc].r < l || stree[plc].l > r) return ;
    	if (stree[plc].l >= l && stree[plc].r <= r)
    	{
    		stree[plc].rel_way = lz_way;
    		stree[plc].rel_num = lz_num;
    		stree[plc].lazy_way = lz_way;
    		stree[plc].lazy_num = lz_num;
    		return ;
    	}
    	pushdown(plc);
    	int mid = (stree[plc].l + stree[plc].r) >> 1;
    	if (mid >= l) update(l, r, lz_way, lz_num, plc << 1);
    	if (mid < r) update(l, r, lz_way, lz_num, plc << 1 | 1);
    }
    
    int query_insert(int pos, int plc)
    {
    	if (plc == 1 && pos >= stree[plc].num) return stree[plc].r + 1; // just differ in here
    	if (stree[plc].l == stree[plc].r) return stree[plc].l;
    	pushdown(plc);
    	int lz_way = stree[plc << 1].lazy_way, lz_num = stree[plc << 1].lazy_num, nm = stree[plc << 1].num;
    	if (lz_way == -1)
    	{
    		if (lz_num <= pos && lz_num + nm > pos)
    		{
    			return query_insert(pos, plc << 1);
    		}
    	}
    	if (lz_way == 1)
    	{
    		if (lz_num > pos && lz_num - nm <= pos)
    		{
    			return query_insert(pos, plc << 1);
    		}
    	}
    	return query_insert(pos, plc << 1 | 1);
    }
    
    int main()
    {
    	scanf("%d", &n);
    	for (int i = 1; i <= n; i ++ )
    	{
    		scanf("%d", &w[i]);
    	}
    	init(1, n, 1);
    	
    	scanf("%d", &q);
    	for (int i = 0; i < q; i ++ )
    	{
    		int op, v;
    		scanf("%d%d", &op, &v);
    		if (op == 1)
    		{
    			if (v == 1) continue;
    			PII mov = query(v, 1);
    			update(1, v - 1, -1, mov.first, 1);
    		}
    		else if (op == 2)
    		{
    			if (v == 1) continue;
    			PII mov = query(v, 1);
    			update(1, v - 1, 1, mov.second, 1);
    		}
    		else
    		{
    			printf("%d\n", n - query_insert(v, 1) + 1);
    		}
    	}
    	
    	return 0;
    }
    
»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I didn't even have time to solve E as I spent a lot of time of D! E is too classic!

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

My issue

Why is my own code for D wrong? In the editorial, it says that we can use floor(sqrt(x)) instead of the function f(x) to compute $$$\lfloor \sqrt{k} \rfloor$$$. But when I use floor(sqrt(x)), the judge result is this. However, when I finish my code according to the editorial, my judge result is this. Could anyone explain the reason please?

  • »
    »
    4 months ago, hide # ^ |
    Rev. 3  
    Vote: I like it 0 Vote: I do not like it

    I feel the same way—something seems off, but I haven't figured out what it is yet.

    Update: Might be the issue relates to floating-point precision