依题意建树即可。 defsolve():n=II()nums=LII()adj=defaultdict(list)foriinrange(n):adj[nums[i]].append((i+1)<<1)adj[nums[i]].append((i+1)<<1|1)q=deque()d=[0for_inrange(2*n+2)]step=0q.append(1)whileq:k=len(q)for_inrange(k):cur=q.popleft()d[cur]=stepforeinadj[...
I could not find the usual discussion post about the most recent atcoder contest, so I'm posting here. How to solve problem G?atcoder, beginner, contest, 294 +13 Ghassane 23 months ago 7 Comments (6) Show archived | Write comment? chromate00 23 months ago, # | +20 G: ...
A - Rightmost一个字符串最右边的 a 是第几个,没有则输出 -1 inline void solve() { string s; cin >> s; reverse(s.begin(), s.end()); if (s.find('a') > s.size()) cout << "-1 &#…
给定一个数组,不改变原顺序,输出是偶数的数。 解题思路 模拟即可。 神奇的代码 #include<bits/stdc++.h> usingnamespacestd; usingLL =longlong; intmain(void){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); intn; cin >> n; while(n--){ intx; cin >> x; if(!(x &1)) co...
We will hold キーエンスプログラミングコンテスト2022(AtCoder Beginner Contest 274). Contest URL: https://atcoder.jp/contests/abc274 Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20221022T2100&p1=248 Duration: 100 minutes Number of Tasks: 8 Writer: Nyaan, kyo...
AtCoder Beginner Contest 273(D-F) D - LRUD Instructions 题意:给一个棋盘,然后给出N个障碍,然后给出Q次移动,给出移动的方向和移动的距离,如果移动的过程中遇到墙或者障碍,就停止,问每次移动之后停下来的位置。 题解:数据是1e9很大,所以肯定不能遍历,但我们可以看到,实际上会出现的障碍只有2e5个,所以我们...
AtCoder Beginner Contest 174 题解 AtCoder Beginner Contest 174 题解C Repsept 知识点:取模对加法和乘法封闭,所以暴力到2×1062\times 10^62×106,一边取模一边特判即可。D - Alter Altar 最终肯定是RRR全在左边,简单证明:假设最终RRR左边的某个位置存在WWW,则该位置右边只能是WWW,然后就是子问题了...
AtCoder Beginner Contest 042题解(ABCD) AtCoder Beginner Contest 042题解(ABCD) 传送门 A - Iroha and Haiku (ABC Edition) 签到题,直接判断是否是两个 5 5 5,一个 7 7 7。 #include<bits/stdc++.h> using namespace std;
AtCoder Beginner Contest 224 问题D:8 Puzzle on Graph 问题描述:在无向图中,9个点和m条边形成,其中有8块拼图分别位于其中8个点上,一个点上没有拼图。每块拼图可移动至没有拼图的点。任务是求解最少操作次数使得第i块拼图位于点i上,若无法实现则输出-1。思路:经典“八数码问题”。使用map...
数组的维度,因此,我们需要想办法将 个背包压缩到一个维度里;注意到 ,也就是说每个背包的容量至多是 ,不超过个位数能够表示的最大数 ,如此一来,我们便可以将这 个背包的状态压缩成一个十进制数的形式;具体地, 表示第一个背包已经装了 容量的物品,第二个背包已经装了 ...