ATC ABC176
本场ABC难度 from AtCoder Problems |
A - Takoyaki Editorial /
Time Limit: 2 sec / Memory Limit: 1024 MB
Problem Statement
Takahashi loves takoyaki - a ball-shaped snack.
With a takoyaki machine, he can make at most $X$ pieces of takoyaki at a time, taking $T$ minutes regardless of the number of pieces to make.
How long does it take to make $N$ takoyaki?
Constraints
- $1 \leq N,X,T \leq 1000$
- All values in input are integers.
我们只需求出Takahashi需要做几次章鱼烧(即$\left(N-1)\right/X+1$次),再将次数$\times T$就好了。
#include <bits/stdc++.h>
using
namespace
std;
int
n,x,t;
int
main()
{
scanf
(
"%d%d%d"
,&n,&x,&t);
printf
(
"%d\n"
,((n-1)/x+1)*t);
return
0;
}
Time Limit: 2 sec / Memory Limit: 1024 MB
Problem Statement
An integer $N$ is a multiple of $9$ if and only if the sum of the digits in the decimal representation of $N$ is a multiple of $9$. Determine whether $N$ is a multiple of $9$.
Constraints
- $0 \leq N < 10^{200000}$
- $N$ is an integer.
#include <bits/stdc++.h>
using
namespace
std;
int
ans;
string s;
int
main()
{
cin >> s;
for
(
int
i=0,len=s.size();i<len;i++)
ans += s[i]-
'0'
;
printf
(ans%9 ?
"No\n"
:
"Yes\n"
);
return
0;
}
Time Limit: 2 sec / Memory Limit: 1024 MB
Problem Statement
$N$ persons are standing in a row. The height of the $i$-th person from the front is $A_i$.
We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:
Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool.
Find the minimum total height of the stools needed to meet this goal.
Constraints
- $1 \leq N \leq 2 \times 10^5$
- $1 \leq A_i \leq 10^9$
- All values in input are integers.
#include <bits/stdc++.h>
using
namespace
std;
int
n,a[200050],maxn;
long
long
ans;
int
main()
{
scanf
(
"%d"
,&n);
for
(
int
i=0;i<n;i++)
{
scanf
(
"%d"
,a+i);
maxn=max(maxn,a[i]);
ans += max(maxn-a[i],0);
}
printf
(
"%lld"
,ans);
return
0;
}
Time Limit: 2 sec / Memory Limit: 1024 MB
Problem Statement
A maze is composed of a grid of $H \times W$ squares - $H$ vertical, $W$ horizontal.
The square at the $i$-th row from the top and the $j$-th column from the left - $(i,j)$ - is a wall if $S_{ij}$ is '#
' and a road if $S_{ij}$ is '.
'.
There is a magician in $(C_h,C_w)$. He can do the following two kinds of moves:
- Move A: Walk to a road square that is vertically or horizontally adjacent to the square he is currently in.
- Move B: Use magic to warp himself to a road square in the $5 \times 5$ area centered at the square he is currently in.
In either case, he cannot go out of the maze.
At least how many times does he need to use the magic to reach $(D_h,D_w)$?
Constraints
- $1 \leq H,W \leq 10^3$
- $1 \leq C_h,D_h \leq H$
- $1 \leq C_w,D_w \leq W$
- $S_{ij}$ is '
#
' or '.
'. - $S_{C_hC_w}$ and $S_{D_hD_w}$ are '.'.
- $(C_h,C_w) \neq (D_h,D_w)$
#
' 代表墙(不可行),'.' 代表路(可行)。一位魔法师站在$(C_h,C_w)$的格子上,可以做以下两种动作:#include <bits/stdc++.h>
using
namespace
std;
const
int
maxn=1050,dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int
n,m,sx,sy,gx,gy,cnt,idx[maxn*maxn],val[maxn*maxn];
bool
vis[maxn*maxn];
vector<
int
> con[maxn*maxn];
string s[maxn];
void
dfs(
int
x,
int
y)
{
if
(x<0 || y<0 || x >= n || y >= m || s[x][y] !=
'.'
|| idx[x*maxn+y])
return
;
con[cnt].push_back(x*maxn+y);
idx[x*maxn+y]=cnt;
for
(
int
i=0;i<4;i++)
dfs(x+dx[i],y+dy[i]);
}
inline
void
bfs()
{
queue<
int
> q;
memset
(val,-1,
sizeof
(val));
vis[idx[sx*maxn+sy]]=
true
;
for
(
auto
v : con[idx[sx*maxn+sy]])
{
val[v]=0;
q.push(v);
}
while
(!q.empty())
{
int
u=q.front();
q.pop();
if
(u == gx*maxn+gy)
return
;
for
(
int
i=-2;i <= 2;i++)
for
(
int
j=-2;j <= 2;j++)
{
int
x=u/maxn+i,y=u%maxn+j;
if
(x >= 0 && y >=0 && x<n && y<m && s[x][y] ==
'.'
&& !vis[idx[x*maxn+y]])
{
vis[idx[x*maxn+y]]=
true
;
for
(
auto
v : con[idx[x*maxn+y]])
{
val[v]=val[u]+1;
q.push(v);
}
}
}
}
}
int
main()
{
scanf
(
"%d%d%d%d%d%d"
,&n,&m,&sx,&sy,&gx,&gy);
sx--,sy--,gx--,gy--;
for
(
int
i=0;i<n;i++)
cin >> s[i];
for
(
int
i=0;i<n;i++)
for
(
int
j=0;j<m;j++)
if
(!idx[i*maxn+j] && s[i][j] ==
'.'
)
{
cnt++;
dfs(i,j);
}
bfs();
printf
(
"%d\n"
,val[gx*maxn+gy]);
return
0;
}
Time Limit: 3 sec / Memory Limit: 1024 MB
Problem Statement
We have a two-dimensional grid with $H \times W$ squares. There are $M$ targets to destroy in this grid - the position of the $i$-th target is $(h_i,w_i)$.
Takahashi will choose one square in this grid, place a bomb there, and ignite it. The bomb will destroy all targets that are in the row or the column where the bomb is placed. It is possible to place the bomb at a square with a target.
Takahashi is trying to maximize the number of targets to destroy. Find the maximum number of targets that can be destroyed.
Constraints
- All values in input are integers
- $1 \leq H,W \leq 3 \times 10^5$
- $1 \leq M \leq \min (H \times W,3 \times 10^5)$
- $1 \leq h_i \leq H$
- $1 \leq w_i \leq W$
- $(h_i,w_i) \neq (h_j,w_j)(i \neq j)$
#include <bits/stdc++.h>
using
namespace
std;
int
n,m,t,x[300050],y[300050],r[300050],c[300050],rm,cm,cr,cc,cnt;
int
main()
{
scanf
(
"%d%d%d"
,&n,&m,&t);
for
(
int
i=0;i<t;i++)
{
scanf
(
"%d%d"
,x+i,y+i);
r[x[i]-1]++;
c[y[i]-1]++;
}
for
(
int
i=0;i<300050;i++)
{
if
(r[i]>rm)
{
cr=1;
rm=r[i];
}
else
if
(r[i] == rm)
cr++;
if
(c[i]>cm)
{
cc=1;
cm=c[i];
}
else
if
(c[i] == cm)
cc++;
}
for
(
int
i=0;i<t;i++)
if
(r[x[i]-1] == rm && c[y[i]-1] == cm)
cnt++;
printf
(
"%d\n"
,rm+cm-(cr*cc == cnt));
return
0;
}
Time Limit: 2 sec / Memory Limit: 1024 MB
Problem Statement
We have $3N$ cards arranged in a row from left to right, where each card has an integer between $1$ and $N$ (inclusive) written on it. The integer written on the $i$-th card from the left is $A_i$.
You will do the following operation $N-1$ times:
- Rearrange the five leftmost cards in any order you like, then remove the three leftmost cards. If the integers written on those three cards are all equal, you gain $1$ point.
After these $N-1$ operations, if the integers written on the remaining three cards are all equal, you will gain $1$ additional point.
Find the maximum number of points you can gain.
Constraints
- $1 \leq N \leq 2000$
- $1 \leq A_i \leq N$
评论
发表评论