이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |