제출 #369169

#제출 시각아이디문제언어결과실행 시간메모리
369169AlmaHandcrafted Gift (IOI20_gift)C++14
0 / 100
1582 ms27756 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 isPossible = true; for (int i = 0; i < r; i++) { if (!isPossible) 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) { isPossible = false; break; } necklace[start] = 0; start++; } } else { // necklace[start] == 1 or -1 (no colour) while (start <= end) { if (necklace[start] == 0) { isPossible = false; break; } necklace[start] = 1; start++; } } } else { // colour = 2 int numBeads = end - start + 1; while (start <= end) { if (necklace[start] == 0) numBeads--; else if (necklace[start] == 1) numBeads++; start++; } if (numBeads == 0 || numBeads == (end - start + 1) * 2) isPossible = false; } } if (!isPossible) 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]; } } craft (s); 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...