codeforces Hello 2022D. The Winter Hike (二位前缀和+思维)

https://codeforces.com/contest/1621/problem/D
D. The Winter Hike
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Circular land is an 2n×2n
grid. Rows of this grid are numbered by integers from 1 to 2n from top to bottom and columns of this grid are numbered by integers from 1 to 2n from left to right. The cell (x,y) is the cell on the intersection of row x and column y for 1≤x≤2n and 1≤y≤2n

.

There are n2
of your friends in the top left corner of the grid. That is, in each cell (x,y) with 1≤x,y≤n

there is exactly one friend. Some of the other cells are covered with snow.

Your friends want to get to the bottom right corner of the grid. For this in each cell (x,y)
with n+1≤x,y≤2n

there should be exactly one friend. It doesn’t matter in what cell each of friends will be.

You have decided to help your friends to get to the bottom right corner of the grid.

For this, you can give instructions of the following types:

You select a row x

. All friends in this row should move to the next cell in this row. That is, friend from the cell (x,y) with 1≤y<2n will move to the cell (x,y+1) and friend from the cell (x,2n) will move to the cell (x,1)
.
You select a row x
. All friends in this row should move to the previous cell in this row. That is, friend from the cell (x,y) with 1<y≤2n will move to the cell (x,y−1) and friend from the cell (x,1) will move to the cell (x,2n)
.
You select a column y
. All friends in this column should move to the next cell in this column. That is, friend from the cell (x,y) with 1≤x<2n will move to the cell (x+1,y) and friend from the cell (2n,y) will move to the cell (1,y)
.
You select a column y
. All friends in this column should move to the previous cell in this column. That is, friend from the cell (x,y) with 1<x≤2n will move to the cell (x−1,y) and friend from the cell (1,y) will move to the cell (2n,y)

. 

Note how friends on the grid border behave in these instructions.
Example of applying the third operation to the second column. Here, colorful circles denote your friends and blue cells are covered with snow.
在这里插入图片描述

You can give such instructions any number of times. You can give instructions of different types. If after any instruction one of your friends is in the cell covered with snow he becomes ill.

In order to save your friends you can remove snow from some cells before giving the first instruction:

You can select the cell (x,y)

that is covered with snow now and remove snow from this cell for cx,y

coins. 

You can do this operation any number of times.

You want to spend the minimal number of coins and give some instructions to your friends. After this, all your friends should be in the bottom right corner of the grid and none of them should be ill.

Please, find how many coins you will spend.
Input

The first line conta

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值