제출 #1361686

#제출 시각아이디문제언어결과실행 시간메모리
1361686lyra_g13Handcrafted Gift (IOI20_gift)C++20
100 / 100
98 ms21192 KiB
#include "gift.h"
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

int construct(int n, int r, vector<int> a, vector<int> b, vector<int> x) {
  vector<pair<ll, ll>> buff1, one, two;
  for (int i = 0; i < r; i++) {
    if (x[i] == 1)
      buff1.push_back({a[i], b[i]});
    else
      two.push_back({a[i], b[i]});

    if (x[i] == 2 and a[i] - b[i] == 0)
      return 0;
  }

  sort(buff1.begin(), buff1.end());
  sort(two.begin(), two.end());

  for (int i = 0; i < buff1.size(); i++) {
    ll start = buff1[i].first;
    ll end = buff1[i].second;
    while (i + 1 < buff1.size() and end >= buff1[i + 1].first) {
      i++;
      end = max(end, buff1[i].second);
    }
    one.push_back({start, end});
  }

  for (int i = 0; i < two.size(); i++) {
    if (one.empty())
      break;
    auto idx = upper_bound(one.begin(), one.end(), make_pair(two[i].first, (ll)1e18)) - one.begin();
    idx--;
    if (idx < 0)
      continue;
    if (one[idx].second >= two[i].second) {
      return 0;
    }
  }

  string s(n, '0');

  ll left = 0;
  ll c = 0;
  for (int i = 0; i < one.size(); i++) {
    ll start = one[i].first;
    ll end = one[i].second;

    if (left < start) {
      for (int i = left; i < start; i++) {
        if (c == 0) {
          s[i] = 'B';
        } else {
          s[i] = 'R';
        }
        c = abs(c - 1);
      }
    }
    for (int i = start; i <= end; i++) {
      if (c == 0) {
        s[i] = 'B';
      } else {
        s[i] = 'R';
      }
    }
    c = abs(c - 1);
    left = end + 1;
  }

  for (int i = left; i < n; i++) {
    if (c == 0) {
      s[i] = 'B';
    } else {
      s[i] = 'R';
    }
    c = abs(c - 1);
  }

  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...