# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
877100 | 2023-11-22T21:13:28 Z | konber | T-Covering (eJOI19_covering) | C++14 | 1000 ms | 784 KB |
#include <iostream> #include <vector> using namespace std; vector<vector<int>> a, grid; vector<pair<int, int>> sp; int K, N, M; int f(int x){ if(x==K) return 0; int i=sp[x].first, j=sp[x].second; int s1=-1, s2=-1, s3=-1, s4=-1; if(i-1>=0 && i+1<M && j-1>=0){ if(grid[i][j]+grid[i-1][j]+grid[i+1][j]+grid[i][j-1]==0){ grid[i][j]=grid[i-1][j]=grid[i+1][j]=grid[i][j-1]=1; int d=f(x+1); if(d!=-1) s1 = a[i][j]+a[i-1][j]+a[i+1][j]+a[i][j-1]+d; grid[i][j]=grid[i-1][j]=grid[i+1][j]=grid[i][j-1]=0; } } if(i-1>=0 && i+1<M && j+1<N){ if(grid[i][j]+grid[i-1][j]+grid[i+1][j]+grid[i][j+1]==0){ grid[i][j]=grid[i-1][j]=grid[i+1][j]=grid[i][j+1]=1; int d=f(x+1); if(d!=-1) s2 = a[i][j]+a[i-1][j]+a[i+1][j]+a[i][j+1]+d; grid[i][j]=grid[i-1][j]=grid[i+1][j]=grid[i][j+1]=0; } } if(j-1>=0 && j+1<N && i+1<M){ if(grid[i][j]+grid[i][j-1]+grid[i][j+1]+grid[i+1][j]==0){ grid[i][j]=grid[i][j-1]=grid[i][j+1]=grid[i+1][j]=1; int d=f(x+1); if(d!=-1) s3 = a[i][j]+a[i][j-1]+a[i][j+1]+a[i+1][j]+d; grid[i][j]=grid[i][j-1]=grid[i][j+1]=grid[i+1][j]=0; } } if(j-1>=0 && j+1<N && i-1>=0){ if(grid[i][j]+grid[i][j-1]+grid[i][j+1]+grid[i-1][j]==0){ grid[i][j]=grid[i][j-1]=grid[i][j+1]=grid[i-1][j]=1; int d=f(x+1); if(d!=-1) s4 = a[i][j]+a[i][j-1]+a[i][j+1]+a[i-1][j]+d; grid[i][j]=grid[i][j-1]=grid[i][j+1]=grid[i-1][j]=0; } } return max(s1, max(s2, max(s3, s4))); } int main() { scanf("%d%d", &M, &N); a.resize(M, vector<int>(N)); grid.resize(M, vector<int>(N)); for(int i=0; i < M; i++){ for(int j=0; j < N; j++) scanf("%d", &a[i][j]); } scanf("%d", &K); sp.resize(K); for(int i=0; i < K; i++){ scanf("%d%d", &sp[i].first, &sp[i].second); } int ans=f(0); if(ans>=0) printf("%d\n", ans); else printf("No\n"); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 344 KB | Output is correct |
2 | Execution timed out | 1068 ms | 604 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 560 KB | Output is correct |
2 | Execution timed out | 1084 ms | 604 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 348 KB | Output is correct |
2 | Execution timed out | 1087 ms | 784 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 344 KB | Output is correct |
2 | Execution timed out | 1034 ms | 344 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 344 KB | Output is correct |
2 | Execution timed out | 1068 ms | 604 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 344 KB | Output is correct |
2 | Execution timed out | 1068 ms | 604 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |