# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
136462 | sebinkim | Connect (CEOI06_connect) | C++14 | 1080 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int D[3030][5050];
char S[33][99];
int n, m;
int main()
{
int i, j, x, y, t;
scanf("%d%d\n", &n, &m);
for(i=0; i<n; i++){
fgets(S[i], 88, stdin);
}
n /= 2; m /= 2;
for(i=0; i<=n*m; i++){
for(j=0; j<(1<<m+1); j++){
D[i][j] = 1e9;
}
}
D[0][0] = 0;
for(i=0; i<n*m; i++){
x = i / m << 1 | 1; y = i % m << 1 | 1;
for(j=0; j<(1<<m+1); j++){
if(S[x][y] == 'X'){
if((j & 3) == 3) continue;
else if(j & 3){
t = j >> 1 & ~1;
D[i + 1][t] = min(D[i + 1][t], D[i][j] + 1);
}
else{
if(S[x][y + 1] != '|'){
t = j >> 1 | 1;
D[i + 1][t] = min(D[i + 1][t], D[i][j] + 1);
}
if(S[x + 1][y] != '-'){
t = j >> 1 & ~1 | 1 << m;
D[i + 1][t] = min(D[i + 1][t], D[i][j] + 1);
}
}
}
else{
if((j & 3) == 3){
t = j >> 1 & ~1;
D[i + 1][t] = min(D[i + 1][t], D[i][j] + 2);
}
else if(j & 3){
if(S[x][y + 1] != '|'){
t = j >> 1 | 1;
D[i + 1][t] = min(D[i + 1][t], D[i][j] + 2);
}
if(S[x + 1][y] != '-'){
t = j >> 1 & ~1 | 1 << m;
D[i + 1][t] = min(D[i + 1][t], D[i][j] + 2);
}
}
else{
t = j >> 1 & ~1;
D[i + 1][t] = min(D[i + 1][t], D[i][j]);
if(S[x][y + 1] != '|' && S[x + 1][y] != '-'){
t = j >> 1 | 1 | 1 << m;
D[i + 1][t] = min(D[i + 1][t], D[i][j] + 2);
}
}
}
}
}
printf("%d\n", D[n * m][0]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |