# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
929197 | 2024-02-17T22:37:00 Z | Stavab | Colouring a rectangle (eJOI19_colouring) | C++14 | 75 ms | 6608 KB |
#include <iostream> using namespace std; #define INF 9999999999999999 int A[200005][2]; int B[200005][2]; long long prSum[200005][2]; int main() { int N, M; scanf("%d %d", &N, &M); int input; if(N > M) { int K = N - M; for(int i = 0; i < 2; i++) { for(int j = 1; j <= 2*N - 1; j++) { if((i == 0 && j <= K) || (i == 1 && 2*N - 1 - j < K)) input = 0; else scanf("%d", &input); if(i == 0) { if(j % 2 == 1) A[(j + 1) / 2][0] = input; else A[j / 2][1] = input; } else { if(j % 2 == 1) B[(j + 1) / 2][0] = input; else B[j / 2][1] = input; } } } } else { int K = M - N; for(int i = 0; i < 2; i++) { for(int j = 1; j <= 2*N - 1; j++) { if((i == 1 && j <= K) || (i == 0 && 2*N - 1 - j < K)) input = 0; else scanf("%d", &input); if(i == 0) { if(j % 2 == 1) A[(j + 1) / 2][0] = input; else A[j / 2][1] = input; } else { if(j % 2 == 1) B[(j + 1) / 2][0] = input; else B[j / 2][1] = input; } } } } for(int i = 0; i < 2; i++) for(int j = 1; j <= N; j++) prSum[j][i] = prSum[j - 1][i] + B[j][i]; long long answer = 0; if(N % 2 == 1) { long long tmpAnswer = INF; long long sum = 0; int size = (N + 1) / 2; for(int j = 0; j < size; j++) { tmpAnswer = min(tmpAnswer, sum + prSum[N - j][0] - prSum[j][0]); if(j == 0) sum += A[size][0]; else { sum += A[size + j][0]; sum += A[size - j][0]; } } tmpAnswer = min(tmpAnswer, sum); answer += tmpAnswer; tmpAnswer = INF; sum = 0; size = (N - 1) / 2; for(int j = 0; j < size; j++) { tmpAnswer = min(tmpAnswer, sum + prSum[N - 1 - j][1] - prSum[j][1]); sum += A[size - j][1]; sum += A[size + 1 + j][1]; } tmpAnswer = min(tmpAnswer, sum); answer += tmpAnswer; } else { long long tmpAnswer = INF; long long sum = 0; int size = N / 2; for(int j = 0; j < size; j++) { tmpAnswer = min(tmpAnswer, sum + prSum[N - j][0] - prSum[j][0]); if(j == 0) sum += A[size][1]; else { sum += A[size + j][1]; sum += A[size - j][1]; } } tmpAnswer = min(tmpAnswer, sum); answer += tmpAnswer; tmpAnswer = INF; sum = 0; size = N / 2; for(int j = 0; j < size; j++) { tmpAnswer = min(tmpAnswer, sum + prSum[N - 1 - j][1] - prSum[j][1]); sum += A[size - j][0]; sum += A[size + 1 + j][0]; } tmpAnswer = min(tmpAnswer, sum); answer += tmpAnswer; } printf("%lld\n", answer); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Incorrect | 1 ms | 2496 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Incorrect | 1 ms | 2496 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Incorrect | 1 ms | 2496 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Incorrect | 1 ms | 2496 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 71 ms | 6484 KB | Output is correct |
2 | Correct | 72 ms | 6484 KB | Output is correct |
3 | Correct | 70 ms | 6608 KB | Output is correct |
4 | Correct | 73 ms | 6596 KB | Output is correct |
5 | Correct | 75 ms | 6564 KB | Output is correct |
6 | Correct | 65 ms | 6600 KB | Output is correct |
7 | Correct | 73 ms | 6588 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2392 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
3 | Correct | 1 ms | 2396 KB | Output is correct |
4 | Incorrect | 1 ms | 2496 KB | Output isn't correct |
5 | Halted | 0 ms | 0 KB | - |