atcoder_official's blog

By atcoder_official, history, 7 months ago, In English

We will hold AtCoder Regular Contest 207 (Div.1).

The point values will be 800-800-800-800-800.

Please note that the rules against generative AI were updated on October 3, 2025. Please make sure to read this post and the rules.

We are looking forward to your participation!

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

»
7 months ago, hide # |
 
Vote: I like it +12 Vote: I do not like it

contest duration: 2025-10-05(Sun) 20:00 — 2025-10-05(Sun) 22:30 (local time) (150 minutes)

but meanwhile, down here:

duration: 120 minutes

so what's the true duration.

»
7 months ago, hide # |
 
Vote: I like it +68 Vote: I do not like it

Interesting score distribution.

»
7 months ago, hide # |
 
Vote: I like it +31 Vote: I do not like it

Why (Do you live in Japan?* -> No) still need Date of birth* ?

»
7 months ago, hide # |
Rev. 3  
Vote: I like it +91 Vote: I do not like it

AtCoder's point values sum (×)

Another ACM-ICPC mode (√)

»
7 months ago, hide # |
 
Vote: I like it +142 Vote: I do not like it

»
7 months ago, hide # |
 
Vote: I like it -16 Vote: I do not like it

That one guy who has the best strat to get most points: WHY IS EVERYTHING 800 >-<

I am the opposite of that one guy :)

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

horrible 800

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

When you want to decide your order of solving problems: 800-800-800-800-800

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

Yet another ICPC round.

ICPC * 800.

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

Welp I failed. Gj to those who even did 1 Q

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

For D, a better way of thinking is to observe that, assume $$$n$$$ is odd, then the winner of the medium row always wins the whole game. In this way, one can naively write a simple dp to calculate the result of the medium row without any further thinking needed.

upd: this solution is not correct, we should keep the medium $$$3$$$ rows and do the dp.

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

    On this test:

    3 2
    11
    00
    11
    

    Second wins on the medium row. However, if First starts by eating a column, they can repeat whatever Second does after, and win the game.

    • »
      »
      »
      7 months ago, hide # ^ |
       
      Vote: I like it +8 Vote: I do not like it

      Oh sorry, the 1 column case should take $$$3$$$ rows into consideration. We should keep the medium $$$3$$$ rows instead of $$$1$$$.

      Actually I proved the $$$3$$$ row case in contest and implemented it. I naively thought this could be brought to the $$$1$$$ row case as well, but it seems not.

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

I reduced Problem A to the following task:

Let $$$w=\sum a - X$$$. Count the number of permutations $$$p$$$ of length $$$n$$$ such that $$$\sum \min(a_i,p_i-1)\ge w$$$.

Clearly $$$w \lt n^2$$$. Since we are counting permutations, this can be converted into counting matchings in a bipartite graph between $$${a_1,a_2,\dots,a_n}$$$ and $$${0,1,2,\dots,n-1}$$$. So I place these $$$2n$$$ numbers together, sort them in nonincreasing order, and decide them one by one. I design a DP state $$$f_{i,j,k,l}$$$ meaning that after processing the first $$$i$$$ elements, there are $$$j$$$ unmatched $$$a_i$$$-type elements and $$$k$$$ unmatched index-type elements; the transitions are:

if (a[i].second == 0) {
    // it means it comes from a[i]
    
    if (k) Add(g[j][k - 1][l + a[i].first], mul(f[j][k][l], k));  // match with an index (p_i-1)
    Add(g[j + 1][k][l], f[j][k][l]); // leave this a[i] unmatched
} else {
    // it means it comes from an index (value i-1)

    if (j) Add(g[j - 1][k][l + a[i].first], mul(f[j][k][l], j));  // match with an a (a_i)
    Add(g[j][k + 1][l], f[j][k][l]); // leave this index unmatched
}

This is $$$O(n^5)$$$. However, if I record which DP states are nonzero and only perform transitions from those states, it surprisingly passes.

Does anyone know why that is? Thanks.

Submission record: https://atcoder.jp/contests/arc207/submissions/69911719

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

    There is a relation between j and k depending on i (for non-zero), so it is n^4 states. But also n^5 can be fast enough for n <= 100

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +8 Vote: I do not like it

    Because the variables j and k can actually be compressed into a single variable M: the number of matched pairs in the prefix.

»
7 months ago, hide # |
 
Vote: I like it +23 Vote: I do not like it

How I solved D...

I got stucked on C and went to D.

I remembered that in the 1D version we only need to look at the (at most) $$$3$$$ characters in the middle.

Then I guessed that we also can just look at the central $$$3\times 3$$$ area in the original problem.

I submitted that algorithm but got WA.

I was disappointed. I thought my algorithm was completely wrong and hopelessly changed the area to $$$4\times 4$$$ then submitted it again.

...Then I got Accepted!

  • »
    »
    7 months ago, hide # ^ |
     
    Vote: I like it +10 Vote: I do not like it

    I solved D in the same way.

    I knew the condition is related to the central grids, and I just took a central rectangle(the size was big enough, like $$$16 \times 16$$$) and run brute force and passed.

    So can anyone prove what size of rectangle is enough?

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

      When $$$n$$$ is even, keep the middle $$$4$$$ rows; when $$$n$$$ is odd, keep the middle $$$3$$$ rows ($$$m$$$ is same). This should be the minimal rectangle.

      According to the official editorial, when exactly one of $$$n$$$ and $$$m$$$ is odd, the answer depends only on the central $$$2\times 3$$$ rectangle.

      When both $$$n$$$ and $$$m$$$ are odd, if the center cell is 0 or the three middle cells are 010, then the second player wins. That means that answer is related to the cross in the middle, which is a central $$$3 \times 3$$$ rectangle; otherwise, by shrinking from one of the four directions to reach a situation where only one side length is odd, one finds that the central $$$2\times 3$$$ rectangle after shrinking corresponds to a contiguous subrectangle of the original central $$$3\times 3$$$ rectangle.

      When both $$$n$$$ and $$$m$$$ are even, we shrink from one of the four directions to obtain a one odd one even case; in that case the central $$$3\times 3$$$ rectangle after shrinking corresponds to a contiguous subrectangle of the original central $$$4\times 4$$$ rectangle.

      Therefore, keeping the middle 4 rows when $$$n$$$ is even and the middle 3 rows when $$$n$$$ is odd is sufficient for this problem.

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

I wrote a strange solution for C and it got AC.Can anybody tell me why the probability of WA is sufficiently low?

Here is the code:

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

For Problem C, I have a solution with a superior time complexity of O(n log V), where V represents the value range, which is more efficient than the one provided in the Editorial. For details, please refer to: https://atcoder.jp/contests/arc207/submissions/69905415

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

    Hello.

    In line 44, if (f[j - 1] > t[j] && f[j - 1] <= (t[j] | a[i])). Why you add f[j - 1] > t[j]? :thinking:

    After testing, i found that remove f[j - 1] > t[j] still can pass.

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

      You're absolutely right. This really isn't necessary. The reason I did it this way is that I initially used a set to maintain 'mx' in a complicated manner, but later removed it.

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

In problem B, I wrote a brute-force to get an answer from 2 to 8. And I find it can be solved by bipartite graph.

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

It could be less rating critera

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

In problem C, I used a very simple approach: let $$$f_i$$$ denote the length of the longest non-decreasing subsequence ending at $$$i$$$, and $$$g_i$$$ denote the minimum value of the last segment in such a subsequence. Then, I performed direct transitions using binary search. This solution passed all test cases, and I want to ask about the correctness of this approach.

Code

#include<bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pb emplace_back
#define ll long long
#define all(b) b.begin(),b.end()
using namespace std;
const int N=2e5+10;
int n,f[N],g[N],a[N],cnt[31][N];
int l1[N],r1[N];
void ck(int i,int w,int d)
{
    if(w>f[i]) f[i]=w,g[i]=d;
    else if(w>=f[i]&&d<g[i]) g[i]=d;
}
void init(int x,int w)
{
    for(int i=0;i<30;i++) cnt[i][x]+=(w>>i&1);
}
inline int calc(int l,int r)
{
    int ans=0;
    for(int i=0;i<30;i++) if(cnt[i][r]-cnt[i][l-1]) ans+=(1<<i);
    return ans;
}
bool check(int i,int x)
{
    int l=l1[x],r=r1[x],ans=-1;
    while(l<=r)
    {
        int mid=l+r>>1;
        if(calc(mid+1,i)>=g[mid]) ans=mid,l=mid+1;
        else r=mid-1;
    }
    if(ans==-1) return 0;
    ck(i,f[ans]+1,calc(ans+1,i));
    return 1;
}
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i],init(i,a[i]);
    for(int i=0;i<30;i++) for(int j=1;j<=n;j++) cnt[i][j]+=cnt[i][j-1];
    for(int i=1;i<=n;i++)
    {
        ck(i,f[i-1],a[i]|g[i-1]);
        if(!check(i,f[i-1])) check(i,f[i-1]-1);
        if(f[i]==f[i-1]) r1[f[i]]=i;
        else l1[f[i]]=r1[f[i]]=i;
    }
    cout<<f[n];
    return 0;
}