ybc2027zhanglingrui @ 2024-03-29 10:49:43
#include<bits/stdc++.h>
using namespace std;
int read() {
int s = 0, w = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') w = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
s = s * 10 + c - '0';
c = getchar();
}
return s * w;
}
void print(int x) {
if (x < 0) { //判负
putchar('-');
x = -x;
}
if (x >= 10)
print(x / 10);
putchar(x % 10 + '0');
return;
}
#define fro(n) for(int i=1;i<=n;i++)
#define ofr(n) for(int i=1;i<=n;i++)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
const double eps = 1e-6;
const int maxn = 1e8;
const int mod = 1e6+7;
const int INF = 0x3f3f3f3f;
const int maxsize = 105;
LL dp[maxsize][maxsize];
struct node{
LL x,y;
LL value;
friend bool operator < (node x,node y){
return x.value > y.value;
}
}a[maxsize][maxsize];
priority_queue <node> p;
void solve();
bool check(int x);
void dfs(int x,int y);
bool cmp(node x,node y);
int main(){
//freopen("001.in","r",stdin);
//freopen("001.out","w",stdout);
LL T = 1;
//scanf("%d",&T);
while(T--){
LL ans = 0;
int n = read(),m= read();
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++){
a[i][j].value = read();
a[i][j].x = i;
a[i][j].y = j;
p.push(a[i][j]);
}
}
while(!p.empty()){
node start = p.top();
if(a[start.x][start.y].value > a[start.x - 1][start.y].value){
dp[start.x][start.y] = max(dp[start.x][start.y],dp[start.x - 1][start.y] + 1);
}
if(a[start.x][start.y].value > a[start.x + 1][start.y].value){
dp[start.x][start.y] = max(dp[start.x][start.y],dp[start.x + 1][start.y] + 1);
}
if(a[start.x][start.y].value > a[start.x][start.y - 1].value){
dp[start.x][start.y] = max(dp[start.x][start.y],dp[start.x][start.y - 1] + 1);
}
if(a[start.x][start.y].value > a[start.x][start.y + 1].value){
dp[start.x][start.y] = max(dp[start.x][start.y],dp[start.x][start.y + 1] + 1);
}
ans = max(ans,dp[start.x][start.y]);
p.pop();
// cout << start.x << " " << start.y << " " << dp[start.x][start.y] << endl;
}
print(ans);
}
return 0;
}
提交记录,题目P1434。
by ybc2027zhanglingrui @ 2024-03-29 10:52:41
现在60分
#include<bits/stdc++.h>
using namespace std;
int read() {
int s = 0, w = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') w = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
s = s * 10 + c - '0';
c = getchar();
}
return s * w;
}
void print(int x) {
if (x < 0) { //判负
putchar('-');
x = -x;
}
if (x >= 10)
print(x / 10);
putchar(x % 10 + '0');
return;
}
#define fro(n) for(int i=1;i<=n;i++)
#define ofr(n) for(int i=1;i<=n;i++)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
const double eps = 1e-6;
const int maxn = 1e8;
const int mod = 1e6+7;
const int INF = 0x3f3f3f3f;
const int maxsize = 105;
LL dp[maxsize][maxsize];
struct node{
LL x,y;
LL value;
friend bool operator < (node x,node y){
return x.value > y.value;
}
}a[maxsize][maxsize];
priority_queue <node> p;
void solve();
bool check(int x);
void dfs(int x,int y);
bool cmp(node x,node y);
int main(){
//freopen("001.in","r",stdin);
//freopen("001.out","w",stdout);
LL T = 1;
//scanf("%d",&T);
while(T--){
LL ans = 0;
int n = read(),m= read();
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++){
a[i][j].value = read();
a[i][j].x = i;
a[i][j].y = j;
p.push(a[i][j]);
}
}
while(!p.empty()){
node start = p.top();
if(a[start.x][start.y].value >= a[start.x - 1][start.y].value){
dp[start.x][start.y] = max(dp[start.x][start.y],dp[start.x - 1][start.y] + 1);
}
if(a[start.x][start.y].value >= a[start.x + 1][start.y].value){
dp[start.x][start.y] = max(dp[start.x][start.y],dp[start.x + 1][start.y] + 1);
}
if(a[start.x][start.y].value >= a[start.x][start.y - 1].value){
dp[start.x][start.y] = max(dp[start.x][start.y],dp[start.x][start.y - 1] + 1);
}
if(a[start.x][start.y].value >= a[start.x][start.y + 1].value){
dp[start.x][start.y] = max(dp[start.x][start.y],dp[start.x][start.y + 1] + 1);
}
ans = max(ans,dp[start.x][start.y]);
p.pop();
// cout << start.x << " " << start.y << " " << dp[start.x][start.y] << endl;
}
print(ans);
}
return 0;
}
by ENJOuYang @ 2024-03-31 23:26:30
@ybc2027zhanglingrui hack:
4 5
0 1 2 3 4
9 8 7 6 5
10 11 12 12 13
18 17 16 15 14
output:
16
@ybc2027zhanglingrui
by ybc2027zhanglingrui @ 2024-03-31 23:28:08
@ENJOuYang Thx,已关