# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
127352 | 2019-07-09T09:12:24 Z | E869120 | DEL13 (info1cup18_del13) | C++14 | 19 ms | 2508 KB |
#include <iostream> #include <algorithm> #include <vector> using namespace std; #pragma warning (disable: 4996) bool forced[1 << 18]; int col[1 << 18], cl[1 << 18], cr[1 << 18]; vector<int> solve(int N, vector<int>A) { if ((N - (int)A.size()) % 2 == 1) return vector<int>{-1}; for (int i = 0; i <= N + 1; i++) { col[i] = -1; cl[i] = (1 << 30); cr[i] = -(1 << 30); forced[i] = false; } for (int i = 0; i < A.size(); i++) { if ((i + 1) % 2 == A[i] % 2) { if (col[A[i]] >= 0) return vector<int>{-1}; else col[A[i]] = i + 1; } else { if (col[A[i] - 1] >= 0 || col[A[i]] >= 0) return vector<int>{-1}; else { col[A[i] - 1] = i + 1; col[A[i]] = i + 1; col[A[i] + 1] = i + 1; } } } for (int i = 1; i <= N - 1; i++) { if (col[i] == -1 || col[i + 1] == -1) continue; if (col[i] != col[i + 1]) { if (col[i] % 2 == A[col[i] - 1] % 2) forced[col[i]] = true; if (col[i + 1] % 2 == A[col[i + 1] - 1] % 2) forced[col[i + 1]] = true; } } if (A[0] == 1) forced[1] = true; if (A[A.size() - 1] == N) forced[A.size()] = true; for (int i = 1; i <= N; i++) { if (col[i] == -1) continue; cl[col[i]] = min(cl[col[i]], i); cr[col[i]] = max(cr[col[i]], i); } for (int i = 1; i < cl[1]; i++) col[i] = 1; for (int i = cr[A.size()] + 1; i <= N; i++) col[i] = A.size(); for (int i = 1; i <= (int)A.size() - 1; i++) { int el = cr[i] + 1, er = cl[i + 1] - 1; if (forced[i] == true) { for (int j = el; j <= er; j++) col[j] = i + 1; } else if (forced[i + 1] == true) { for (int j = el; j <= er; j++) col[j] = i; } else { for (int j = el; j <= (el + er) / 2; j++) col[j] = i; for (int j = (el + er) / 2 + 1; j <= er; j++) col[j] = i + 1; } } for (int i = 1; i <= N; i++) { cl[col[i]] = min(cl[col[i]], i); cr[col[i]] = max(cr[col[i]], i); } vector<int>ans; for (int i = 1; i <= A.size(); i++) { if (cl[i] == cr[i]) continue; int lefthand = A[i - 1] - cl[i], righthand = cr[i] - A[i - 1]; if (lefthand == 0 || righthand == 0) return vector<int>{-1}; if ((cr[i] - cl[i]) % 2 == 1) return vector<int>{-1}; if (lefthand <= righthand) { int mid = cr[i] - (righthand - lefthand) / 2; for (int j = 0; j < (righthand - lefthand) / 2; j++) ans.push_back(mid); for (int j = 0; j < lefthand; j++) ans.push_back(A[i - 1]); } if (lefthand > righthand) { int mid = cl[i] + (lefthand - righthand) / 2; for (int j = 0; j < (lefthand - righthand) / 2; j++) ans.push_back(mid); for (int j = 0; j < righthand; j++) ans.push_back(A[i - 1]); } } return ans; } int main() { int T; scanf("%d", &T); for (int i = 1; i <= T; i++) { int N1, V1; vector<int>A1; scanf("%d%d", &N1, &V1); for (int j = 1; j <= V1; j++) { int p; scanf("%d", &p); A1.push_back(p); } vector<int>L = solve(N1, A1); if (L == vector<int>{-1}) printf("-1\n"); else { printf("%d\n", (int)L.size()); for (int j = 0; j < L.size(); j++) { if (j) printf(" "); printf("%d", L[j]); } printf("\n"); } } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 376 KB | Output isn't correct |
2 | Runtime error | 3 ms | 508 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 376 KB | Output isn't correct |
2 | Runtime error | 3 ms | 508 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
3 | Incorrect | 9 ms | 504 KB | Output isn't correct |
4 | Incorrect | 9 ms | 376 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 632 KB | Output is correct |
2 | Correct | 4 ms | 420 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 376 KB | Output isn't correct |
2 | Runtime error | 3 ms | 508 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
3 | Incorrect | 9 ms | 504 KB | Output isn't correct |
4 | Incorrect | 9 ms | 376 KB | Output isn't correct |
5 | Incorrect | 3 ms | 376 KB | Output isn't correct |
6 | Runtime error | 3 ms | 504 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
7 | Incorrect | 3 ms | 376 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 376 KB | Output isn't correct |
2 | Runtime error | 3 ms | 508 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
3 | Incorrect | 9 ms | 504 KB | Output isn't correct |
4 | Incorrect | 9 ms | 376 KB | Output isn't correct |
5 | Incorrect | 3 ms | 376 KB | Output isn't correct |
6 | Runtime error | 3 ms | 504 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
7 | Incorrect | 3 ms | 376 KB | Output isn't correct |
8 | Incorrect | 10 ms | 760 KB | Output isn't correct |
9 | Incorrect | 11 ms | 1144 KB | Output isn't correct |
10 | Incorrect | 11 ms | 1400 KB | Output isn't correct |
11 | Incorrect | 19 ms | 2508 KB | Output isn't correct |