QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227346 | #3425. Coast Length | Bashca# | AC ✓ | 21ms | 44860kb | C++23 | 767b | 2023-10-27 12:49:21 | 2023-10-27 12:49:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1002;
char s[maxn][maxn];
bool vis[maxn][maxn];
int n, m;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int dfs(int x, int y) {
vis[x][y] = 1;
int ans = 0;
for (int i=0; i<4; ++i) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || ny < 0) continue;
if (nx > n + 1 || ny > m + 1) continue;
if (s[nx][ny] == '1') ans += 1;
else if (!vis[nx][ny]) ans += dfs(nx, ny);
}
return ans;
}
int main() {
scanf("%d%d", &n, &m);
memset(s, '0', sizeof s);
for (int i=1; i<=n; ++i) {
scanf("%s", s[i]+1);
s[i][m+1] = '0';
}
cout << dfs(0, 0) << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4744kb
input:
1 1 1
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4592kb
input:
1 1 0
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 4712kb
input:
2 1 1 0
output:
4
result:
ok single line: '4'
Test #4:
score: 0
Accepted
time: 1ms
memory: 4800kb
input:
1 2 11
output:
6
result:
ok single line: '6'
Test #5:
score: 0
Accepted
time: 0ms
memory: 4708kb
input:
2 2 10 01
output:
8
result:
ok single line: '8'
Test #6:
score: 0
Accepted
time: 1ms
memory: 4728kb
input:
3 3 111 101 111
output:
12
result:
ok single line: '12'
Test #7:
score: 0
Accepted
time: 1ms
memory: 4804kb
input:
3 3 100 010 010
output:
10
result:
ok single line: '10'
Test #8:
score: 0
Accepted
time: 1ms
memory: 4784kb
input:
7 7 1000000 1011110 1010010 1011010 1000010 1111110 0000000
output:
44
result:
ok single line: '44'
Test #9:
score: 0
Accepted
time: 1ms
memory: 4808kb
input:
3 3 111 101 111
output:
12
result:
ok single line: '12'
Test #10:
score: 0
Accepted
time: 0ms
memory: 4812kb
input:
10 10 1011001100 1100010010 0110111111 1010101011 1110001111 0011001000 0011011011 1100100010 1111110100 1100100010
output:
92
result:
ok single line: '92'
Test #11:
score: 0
Accepted
time: 1ms
memory: 4660kb
input:
10 10 0101111111 1011101111 1100111111 1111111001 0010110011 1110010001 1101111111 1111011111 1011011111 1110100101
output:
52
result:
ok single line: '52'
Test #12:
score: 0
Accepted
time: 1ms
memory: 4736kb
input:
10 10 0000010000 0010001000 1000101001 0000000000 0110100010 1010000100 1000000101 0000000010 0000000010 0000010000
output:
68
result:
ok single line: '68'
Test #13:
score: 0
Accepted
time: 2ms
memory: 6428kb
input:
201 251 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 1111111111111111111111111111111111111111...
output:
3588
result:
ok single line: '3588'
Test #14:
score: 0
Accepted
time: 4ms
memory: 9232kb
input:
400 300 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
3404
result:
ok single line: '3404'
Test #15:
score: 0
Accepted
time: 0ms
memory: 6196kb
input:
200 320 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
7372
result:
ok single line: '7372'
Test #16:
score: 0
Accepted
time: 10ms
memory: 35312kb
input:
1000 1000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
999002
result:
ok single line: '999002'
Test #17:
score: 0
Accepted
time: 8ms
memory: 34912kb
input:
1000 1000 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
999002
result:
ok single line: '999002'
Test #18:
score: 0
Accepted
time: 3ms
memory: 5900kb
input:
1000 1000 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
3996
result:
ok single line: '3996'
Test #19:
score: 0
Accepted
time: 6ms
memory: 6176kb
input:
1000 1000 10011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110...
output:
1001000
result:
ok single line: '1001000'
Test #20:
score: 0
Accepted
time: 11ms
memory: 44860kb
input:
1000 1000 01111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
3996
result:
ok single line: '3996'
Test #21:
score: 0
Accepted
time: 9ms
memory: 10360kb
input:
1000 1000 00111110111111100000001000111111000111000111110011111000000111111000000001111111111000011111111001110011110011111111110000011111111111111100011110111110001110000000111111111000000000010000000001111110011000011111110001111000011111000000000000001111111111110011111100000000111101111111111110...
output:
362014
result:
ok single line: '362014'
Test #22:
score: 0
Accepted
time: 3ms
memory: 5964kb
input:
1000 1000 01111110001101111011011011110100101000111111011001100110101111111101101000010000111101000010111110111010100000101110110001111011010111010100011000010011011111010100010110010010000101101000011011100110100001011101000010101010000011001011110101001100001101010010001101000111000010001010110111...
output:
21242
result:
ok single line: '21242'
Test #23:
score: 0
Accepted
time: 21ms
memory: 20328kb
input:
999 999 0001000111000000011000010000000001111111010111100100000010010011001011000000000100000000010100101000010011000010100001011011000010010100000100100100000100010010100000010100010001000000111010000000100101001100110001101011000010000010001110110110110000100001000000101001101001011111001110000010...
output:
802314
result:
ok single line: '802314'
Test #24:
score: 0
Accepted
time: 1ms
memory: 4848kb
input:
1 1000 11111111011110111101111111001011101011111011001110010100111111111000110101001111111011101011110101011111101101101000010111110111001101110011101111000111111101100010110011001011110000101001001101010001011101100011111011011111101110101101101000110000000111000111111111101011111101011000001101111...
output:
1790
result:
ok single line: '1790'
Test #25:
score: 0
Accepted
time: 1ms
memory: 5912kb
input:
1000 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0...
output:
186
result:
ok single line: '186'