当前位置:网站首页>C. Robot in a Hallway Educational Codeforces Round 133 (Rated for Div. 2)dp
C. Robot in a Hallway Educational Codeforces Round 133 (Rated for Div. 2)dp
2022-08-06 01:32:00 【Salted egg_dd】
dp problem
There is a grid, consisting of 22 rows and mm columns. The rows are numbered from 11 to 22 from top to bottom. The columns are numbered from 11 to mm from left to right.
The robot starts in a cell (1,1)(1,1). In one second, it can perform either of two actions:
- move into a cell adjacent by a side: up, right, down or left;
- remain in the same cell.
The robot is not allowed to move outside the grid.
Initially, all cells, except for the cell (1,1)(1,1), are locked. Each cell (i,j)(i,j) contains a value ai,jai,j — the moment thatthis cell gets unlocked. The robot can only move into a cell (i,j)(i,j) if at least ai,jai,j seconds have passed before the move.
The robot should visit all cells without entering any cell twice or more (cell (1,1)(1,1) is considered entered at the start). It can finish in any cell.
What is the fastest the robot can achieve that?
Input
The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of testcases.
The first line of each testcase contains a single integer mm (2≤m≤2⋅1052≤m≤2⋅105) — the number of columns of the grid.
The ii-th of the next 22 lines contains mm integers ai,1,ai,2,…,ai,mai,1,ai,2,…,ai,m (0≤ai,j≤1090≤ai,j≤109) — the moment of time each cell gets unlocked. a1,1=0a1,1=0. If ai,j=0ai,j=0, then cell (i,j)(i,j) is unlockedfrom the start.
The sum of mm over all testcases doesn't exceed 2⋅1052⋅105.
Output
For each testcase, print a single integer — the minimum amount of seconds that the robot can take to visit all cells without entering any cell twice or more.
Example
input
Copy
430 0 14 3 250 4 8 12 162 6 10 14 1840 10 10 1010 10 10 1020 00 0output
Copy
519173
#include using namespace std;const int N=200010;int a[4][N];int dp[4][N];int main(){int t,m,i,j;scanf("%d",&t);while(t--){scanf("%d",&m);for(i=1;i<=2;i++)for(j=1;j<=m;j++)scanf("%d",&a[i][j]);a[1][1]=-1;dp[1][m+1]=dp[2][m+1]=1;for(j=m;j>=1;j--)for(i=1;i<=2;i++)dp[i][j]=max(max(a[i][j]+2*(m-j+1),a[3-i][j]+1),dp[i][j+1]+1);int ans=5e9;int num=0;for(j=1;j<=m;j++){int k=3-(j%2+1);ans=min(ans,max(num,dp[k][j]));num=max(num,a[k][j]+2*(m-j+1));num=max(num,a[3-k][j]+2*(m-j+1)-1);}cout< 边栏推荐
- 2022 The 4th Shandong International Health Industry Expo, China Health Industry Exhibition
- ERP inventory management
- Kubernetes证书过期怎么玩
- Facial Expression Recognition---Study Notes
- The correct posture for Internet workers to write weekly reports
- STM32与K210串口通信的解码问题(基于正点原子源码)
- 字符编码的历史与发展(ASCII, GBK, Unicode)
- Convert the children array to a one-bit array
- typescript69-类型声明文件概述
- js 实现千分位
猜你喜欢

session、cookie的区别

BugKu:Web

k线图怎么看止损位置

Huawei Analysis & Intermodal Activities to Help You Improve Overall Game Payments

eslint和prettier实现代码格式化

sqli-labs(安装与配置)报错原因

transceiver toolkit使用说明

Kubernetes Cilium展示

The miniPCIe interface CAN card quickly expands the CAN channel for the industrial computer

Raj take-out day01 】 : overall introduction and development environment set up
随机推荐
【树上差分】CF 1076E. Vasya and a Tree
golang pprof 实战
transceiver toolkit使用说明
剑指offer第24题(反转链表)
高数_复习_第2章:一元函数微分学
typescript72-已有的类型声明文件(第三方库的类型文件)
STM32与K210串口通信的解码问题(基于正点原子源码)
typescript70-ts中的两种文件类型
2022 The 4th Shandong International Health Industry Expo, China Health Industry Exhibition
DAY24:信息搜集
Horizontal Federated Learning - Gradient Safe Aggregation 1
Compose 进阶挑战来啦!直播预告|8 月 7 日 晚 19:30 与 GDE 导师面对面
(3.2) Metasploit kali - the exploit 】 【 basis (under) : MSF terminal using process
组织结构图OrgChart.js
EasyCVR通过进程启动无报错,但是自动退出该如何解决?
网页使用微信扫码登录
海康威视秋招正式开始,快来和我做同事~
The correct posture for Internet workers to write weekly reports
eBay, Amazon, Lazada, Shopee, AliExpress, Meikeduo and other cross-border e-commerce platforms, what conditions do I need to meet to evaluate the self-supporting account?How to optimize listing?
deque(双端数组)——STL