제출 #369177

#제출 시각아이디문제언어결과실행 시간메모리
369177AlmaHandcrafted Gift (IOI20_gift)C++14
0 / 100
1 ms364 KiB
#include <iostream> #include <cmath> #include <vector> #include <algorithm> #include "gift.h" using namespace std; int construct(int n, int r, vector<int> a, vector<int> b, vector<int> x) { vector<pair<int, pair<int, int>>> requirements (r); for (int i = 0; i < r; i++) { requirements[i] = make_pair(x[i], make_pair(a[i], b[i])); } sort(requirements.begin(), requirements.end()); vector<int> necklace (n, -1); // blue = 0, red = 1 bool notPossible = false; for (int i = 0; i < r; i++) { if (notPossible) break; int colour = requirements[i].first; int start = requirements[i].second.first; int end = requirements[i].second.second; if (colour == 1) { if (necklace[start] == 0) { start++; while (start <= end) { if (necklace[start] == 1) { notPossible = true; break; } necklace[start] = 0; start++; } } else { // necklace[start] == 1 or -1 (no colour) while (start <= end) { if (necklace[start] == 0) { notPossible = true; break; } necklace[start] = 1; start++; } } } else { // colour = 2 int numBeads = end - start + 1; int startToEnd = numBeads; while (start <= end) { if (necklace[start] == 0) numBeads--; else if (necklace[start] == 1) numBeads++; start++; } if (numBeads == 0 || numBeads == (startToEnd) * 2) notPossible = true; } } if (notPossible) return 0; string s (n, ' '); char prevColour = 'B'; for (int i = 0; i < n; i++) { if (necklace[i] == 0) { s[i] = 'B'; prevColour = 'B'; } else if (necklace[i] == 1) { s[i] = 'R'; prevColour = 'R'; } else { // necklace[i] == -1 if (prevColour == 'B') s[i] = 'R'; else s[i] = 'B'; prevColour = s[i]; } } return 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...