ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#373 | #42. 「NOIP2010」引水入城 | Pigsyy | 100 | 911ms | 7672kb | C++23 | 2.1kb | 2025-04-22 13:40:31 | 2025-04-22 13:42:17 |
answer
#include <bits/stdc++.h>
#define pr pair<int,int>
using namespace std;
const int N = 500 + 10;
int n, m, a[N][N], vis[N][N], ck[N][N], f[N][N];
int fx[10 + 10][10 + 10] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
queue<pr> p;
int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
s = s * 10 + (ch - '0'), ch = getchar();
return s * w;
}
void work(int j) {
p.push(make_pair(1, j));
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
vis[i][j] = 0;
vis[1][j] = 1;
while (!p.empty()) {
pr u = p.front();
p.pop();
if (u.first == n)
ck[j][u.second] = 1;
for (int i = 0; i < 4; ++i) {
int xx = u.first + fx[i][0];
int yy = u.second + fx[i][1];
if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && !vis[xx][yy] && a[u.first][u.second] > a[xx][yy]) {
vis[xx][yy] = 1;
p.push(make_pair(xx, yy));
}
}
}
}
int main() {
n = read(), m = read();
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
a[i][j] = read();
for (int i = 1; i <= m; ++i)
work(i);
memset(f, 0x3f, sizeof(f));
f[0][0] = 0;
for (int i = 0; i < m; ++i)
for (int j = 0; j <= m; ++j) {
f[i + 1][j] = min(f[i + 1][j], f[i][j]);
int p = j;
while (p + 1 <= m && ck[i + 1][p + 1])
p++;
f[i + 1][p] = min(f[i + 1][p], f[i][j] + 1);
}
if (f[m][m] < f[m + 1][m + 1])
printf("1\n%d", f[m][m]);
else {
printf("0\n");
int ans = 0;
for (int i = 1; i <= m; ++i) {
bool flag = false;
for (int j = 1; j <= m; ++j)
flag |= ck[j][i];
if (!flag)
ans++;
}
printf("%d", ans);
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 6456kb
input:
10 10 517 626 565 502 512 551 622 557 518 621 515 498 463 456 507 504 452 598 450 454 432 537 522 41...
output:
0 7
result:
ok 2 tokens
Test #2:
score: 10
Accepted
time: 15ms
memory: 6748kb
input:
100 100 8000 7999 7998 7997 7996 7995 7994 7993 7992 7991 7990 7989 7988 7987 7986 7985 7984 7983 79...
output:
0 53
result:
ok 2 tokens
Test #3:
score: 10
Accepted
time: 816ms
memory: 7672kb
input:
500 500 200000 199999 199998 199997 199996 199995 199994 199993 199992 199991 199990 199989 199988 1...
output:
0 269
result:
ok 2 tokens
Test #4:
score: 10
Accepted
time: 1ms
memory: 6588kb
input:
1 10 109 108 101 100 102 104 104 102 102 105
output:
1 4
result:
ok 2 tokens
Test #5:
score: 10
Accepted
time: 2ms
memory: 6584kb
input:
10 10 1004 1004 1004 1004 1009 1009 1009 1009 1009 1009 904 904 904 904 904 904 904 904 904 904 800 ...
output:
1 6
result:
ok 2 tokens
Test #6:
score: 10
Accepted
time: 1ms
memory: 6544kb
input:
100 20 300 1 1 1 1 1 10009 10009 10009 10009 10009 10009 10009 10009 10009 10009 10009 10009 10009 1...
output:
1 9
result:
ok 2 tokens
Test #7:
score: 10
Accepted
time: 2ms
memory: 6764kb
input:
100 50 300 1 1 1 1 1 300 1 1 1 1 1 10006 10006 10006 10006 10006 10006 10006 10006 10006 10006 10006...
output:
1 21
result:
ok 2 tokens
Test #8:
score: 10
Accepted
time: 1ms
memory: 6680kb
input:
100 100 300 1 1 1 1 1 300 1 1 1 1 1 300 1 1 1 1 1 10004 10004 10004 10004 10004 10004 10004 10004 10...
output:
1 28
result:
ok 2 tokens
Test #9:
score: 10
Accepted
time: 15ms
memory: 6956kb
input:
200 200 600 1 1 1 1 1 600 1 1 1 1 1 20005 20005 20005 20005 20005 20005 20005 20005 20005 20005 2000...
output:
1 41
result:
ok 2 tokens
Test #10:
score: 10
Accepted
time: 58ms
memory: 7476kb
input:
500 500 1500 1 1 1 1 1 1500 1 1 1 1 1 50005 50005 50005 50005 50005 50005 50005 50005 50005 50005 50...
output:
1 86
result:
ok 2 tokens