AtCoder ABC486 Solution (A~D)
Difference between en5 and en6, changed 791 character(s)
AUpdate: Fixed ambiguous wording and added time complexity.↵
↵
- - -↵
↵
[A](https://atcoder.jp/contests/abc486/tasks/abc486_a)
↵
==================↵
↵
Process the characters in order: replace `A` with `Alpha`, `B` with `Bravo`, and `C` with `Charlie`. 
Remember to read $N$ (I got a time penalty here)Time complexity $\mathcal O(N)$.↵
↵
### [Code](https://atcoder.jp/contests/abc486/submissions/81122337)↵
↵
~~~~cpp↵
#include<bits/stdc++.h>↵
using namespace std;↵
int main(){↵
  ios::sync_with_stdio(false);↵
  cin.tie(nullptr),cout.tie(nullptr);↵
  int n;↵
  cin>>n;↵
  string s;↵
  cin>>s;↵
  for(char c:s){↵
    if(c=='A'){↵
      cout<<"Alpha ";↵
    }else if(c=='B'){↵
      cout<<"Bravo ";↵
    }else cout<<"Charlie ";↵
  }↵
  return 0;↵
}↵
~~~~↵
↵
B[B](https://atcoder.jp/contests/abc486/tasks/abc486_b)↵
==================↵
↵
We can use a boolean array $\texttt{vis}$. For each input $A_i$, set $\texttt{vis}_{A_i}=1$. For each subsequent $X_i$ and $Y_i$, set $\texttt{vis}_{X_i}=0$ and $\texttt{vis}_{Y_i}=1$. Finally, output 
$\sum\limits_{i=1}^{100} \texttt{vis}_i$.all indices $i$ for which $\texttt{vis}_i=1$. Time complexity $\mathcal O(N+M)$.↵
↵
↵
### [Code](https://atcoder.jp/contests/abc486/submissions/81129275)↵
↵
~~~~cpp↵
#include<bits/stdc++.h>↵
using namespace std;↵
int a[int(5e5+5)];↵
bitset<int(5e5+5)> vis;↵
int main(){↵
  ios::sync_with_stdio(false);↵
  cin.tie(nullptr),cout.tie(nullptr);↵
  int n,m;↵
  cin>>n>>m;↵
  for(int i=1;i<=n;i++){↵
    cin>>a[i];↵
    vis[a[i]]=1;↵
  }↵
  for(int i=1,x,y;i<=m;i++){↵
    cin>>x>>y;↵
    vis[x]=0,vis[y]=1;↵
  }↵
  for(int i=1;i<=100;i++){↵
    if(vis[i])cout<<i<<' ';↵
  }↵
  return 0;↵
}↵
~~~~↵
↵
C↵
==================↵
↵
If we encounter an `o`, then we add $1$ to
[C](https://atcoder.jp/contests/abc486/tasks/abc486_c)↵
==================↵
↵
For each position $i$ with $s_i=$ `o`, increment
 the answer, and then change this cell and every cell after it at intervals of $k$ to `.`mark $s_i, s_{i+K}, s_{i+2K}, \dots$ as `.` as long as those positions are still `o`. Time complexity $\mathcal O\left(N+\dfrac{N}{K}\right)$.↵
↵
### [Code](https://atcoder.jp/contests/abc486/submissions/81142299)↵
↵
~~~~cpp↵
#include<bits/stdc++.h>↵
using namespace std;↵
int a[int(5e5+5)];↵
bitset<int(5e5+5)> vis;↵
int main(){↵
  ios::sync_with_stdio(false);↵
  cin.tie(nullptr),cout.tie(nullptr);↵
  int n,k,ans=0;↵
  string s;↵
  cin>>n>>k>>s;↵
  for(int i=0;i<n;i++){↵
    if(s[i]=='.')continue;↵
    for(int j=i;j<n&&s[j]=='o';j+=k){↵
      s[j]='.';↵
    }↵
    ans++;↵
  }↵
  cout<<ans;↵
  return 0;↵
}↵
~~~~↵
↵
D[D](https://atcoder.jp/contests/abc486/tasks/abc486_d)↵
==================↵
↵
D $<$ C.↵
↵
Obviously, this is a 0-1 knapsack problem. For each monster that can be defeated, handle it as in 0-1 knapsack: if defeating it is better, defeat it; otherwise, do not. Finally, enumerate the level after defeating the first $N-1$ monsters. If that level is sufficient to defeat the $N$-th monster, update the answer with the current stamina consumption plus the consumption of the $N$-th monster, and take the minimum. Time complexity $\mathcal O(N^2)$.↵
↵
### [Code](https://atcoder.jp/contests/abc486/submissions/81149378)↵
↵
~~~~cpp↵
#include<bits/stdc++.h>↵
#define int int_fast64_t↵
using namespace std;↵
int dp[6005];↵
int l[6005],p[6005];↵
int32_t main(){↵
    cin.tie(0)->sync_with_stdio(0);↵
    cout.tie(0);↵
    int n;↵
    cin>>n;↵
    for(int i=1;i<=n;i++){↵
      cin>>l[i]>>p[i];↵
    }↵
    memset(dp,0x3f,sizeof dp);↵
    dp[1]=0;↵
    for(int i=1;i<=n;i++){↵
      for(int j=i;j;j--){↵
        if(j>=l[i]&&dp[j]!=0x3f3f3f3f3f3f3f3f){↵
          dp[j+1]=min(dp[j+1],dp[j]+p[i]);↵
        }↵
      }↵
    }↵
    int ans=0x3f3f3f3f3f3f3f3f;↵
    for(int i=1;i<=n;i++){↵
      if(i>=l[n]&&dp[i]!=0x3f3f3f3f3f3f3f3f){↵
        ans=min(ans,dp[i]+p[n]);↵
      }↵
    }↵
    cout<<((ans==0x3f3f3f3f3f3f3f3f)?-1:ans);↵
    return 0;↵
}↵
~~~~
↵
↵
- - -↵
↵
<span class="tex-span">In the end, if there are any mistakes, please feel free to point them out.</span>

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en6 English longyitongxue 2026-11-29 09:03:34 791
en5 English longyitongxue 2026-11-28 17:36:09 0 (published)
en4 English longyitongxue 2026-11-28 17:35:41 1257
en3 English longyitongxue 2026-11-28 17:28:39 636
en2 English longyitongxue 2026-11-28 17:06:50 779
en1 English longyitongxue 2026-11-28 16:59:35 622 Initial revision (saved to drafts)