WA#1#3,TLE#2#10

P1434 [SHOI2002] 滑雪

mediocre_ @ 2023-07-21 20:02:22

#include<bits/stdc++.h>
using namespace std;
const int N = 1005;
const int fx[4] = {-1, 0, 0, 1};
const int fy[4] = {0, -1, 1, 0};
struct Node {
    int x, y;
};
queue <Node> q;
int n, m, a[N][N], cis[N][N], ans;
bool vis[N][N];
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            scanf("%d", &a[i][j]);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j) {
            memset(vis, 0, sizeof(vis));
            memset(cis, 0, sizeof(cis));
            cis[i][j] = 1;
            q.push(Node{i, j});
            while (!q.empty()) {
                Node u = q.front();
                q.pop();
                for (int k = 0; k < 4; ++k) {
                    int nx = u.x + fx[k];
                    int ny = u.y + fy[k];
                    if (a[nx][ny] < a[u.x][u.y] && !vis[nx][ny]) {
                        vis[nx][ny] = true;
                        cis[nx][ny] = cis[u.x][u.y] + 1;
                        q.push(Node{nx, ny});
                    }
                }
            }
            for (int k = 1; k <= n; ++k)
                for (int l = 1; l <= n; ++l)
                    ans = max(ans, cis[k][l]);
        }
    printf("%d", ans);
    return 0;
}

by mediocre_ @ 2023-07-21 20:03:18

话说我连样例都过不了还能得60pts


by mediocre_ @ 2023-07-21 20:09:06

上面搞错了

#include<bits/stdc++.h>
using namespace std;
const int N = 1005;
const int fx[4] = {-1, 0, 0, 1};
const int fy[4] = {0, -1, 1, 0};
struct Node {
    int x, y;
};
queue <Node> q;
int n, m, a[N][N], cis[N][N], ans;
bool vis[N][N];
bool inmap(int x, int y) {
    return x >= 1 && y >= 1 && x <= n && y <= m; 
}
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            scanf("%d", &a[i][j]);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j) {
            memset(vis, 0, sizeof(vis));
            memset(cis, 0, sizeof(cis));
            cis[i][j] = 1;
            q.push(Node{i, j});
            while (!q.empty()) {
                Node u = q.front();
                q.pop();
                for (int k = 0; k < 4; ++k) {
                    int nx = u.x + fx[k];
                    int ny = u.y + fy[k];
                    if (a[nx][ny] < a[u.x][u.y] && !vis[nx][ny] && inmap(nx, ny)) {
                        vis[nx][ny] = true;
                        cis[nx][ny] = cis[u.x][u.y] + 1;
                        q.push(Node{nx, ny});
                    }
                }
            }
            for (int k = 1; k <= n; ++k)
                for (int l = 1; l <= m; ++l)
                    ans = max(ans, cis[k][l]);
        }
    printf("%d", ans);
    return 0;
}

by mediocre_ @ 2023-07-21 20:09:19

可是还是60pts


|