Submission #369177

# Submission time Handle Problem Language Result Execution time Memory
369177 2021-02-20T17:15:44 Z Alma Handcrafted Gift (IOI20_gift) C++14
0 / 100
1 ms 364 KB
#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
1 Incorrect 1 ms 364 KB Unknown character at position 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Unknown character at position 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Unknown character at position 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Unknown character at position 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Unknown character at position 0
2 Halted 0 ms 0 KB -