Submission #288476

#TimeUsernameProblemLanguageResultExecution timeMemory
288476TangentPaint By Numbers (IOI16_paint)C++17
32 / 100
1 ms384 KiB
#include "paint.h"
#include <bits/stdc++.h>

using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(), order_of_key()

typedef long long ll;
typedef long double dd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<dd, dd> pdd;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<dd> vdd;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<vdd> vvdd;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
typedef vector<vpdd> vvpdd;
typedef vector<bool> vb;

const int inf = 1 << 30;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define ffor(i, a, b) for(ll i = a; i < b; i++)
#define forin(x, a) for (auto &x: a)
#define all(x) x.begin(), x.end()

#ifdef TEST
#define dbg(x) cout << #x << ": " << x << '\n';
#define dbgc(x) cout << #x << ":"; forin(a, x) { cout << " " << a; } cout << endl;
#define tassert(x) assert(x);
#else
#define dbg(x)
#define dbgc(x)
#define tassert(x)
#endif

std::string solve_puzzle(std::string s, std::vector<int> c) {
  int tot = 0;
  vii l, r;
  forin(x, c) {
    l.emplace_back(tot);
    tot += x + 1;
  }
  string res = s;
  int slack = s.size() - tot + 1;
  rep(i, l.size()) {
    r.emplace_back(l[i] + c[i] + slack - 1);
  }
  vpii rem;
  int j = 0;
  rep(i, s.size()) {
    if (s[i] == '_') {
      while (r[j] < i) {
        l[j + 1] = max(l[j + 1], l[j] + c[j] + 1);
        j++;
      }
      if (i < l[j] + c[j]) {
        l[j] = i + 1;
      }
    }
  }

  j = l.size() - 1;
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == '_') {
      while (l[j] > i) {
        r[j - 1] = min(r[j - 1], r[j] - c[j] - 1);
        j--;
      }
      if (i > r[j] - c[j]) {
        r[j] = i - 1;
      }
    }
  }

  rep(i, l.size()) {
    int cslack = r[i] - l[i] + 1 - c[i];
    ffor(j, l[i], l[i] + cslack) {
      if (res[j] == '.') {
        res[j] = '?';
      }
    }
    ffor(j, l[i] + cslack, r[i] - cslack + 1) {
      res[j] = 'X';
    }
    ffor(j, r[i] - cslack + 1, r[i] + 1) {
      if (res[j] == '.') {
        res[j] = '?';
      }
    }
  }
  rep(i, res.size()) {
    if (res[i] == '.') {
      res[i] = '_';
    }
  }

  return res;
}

Compilation message (stderr)

paint.cpp: In function 'std::string solve_puzzle(std::string, std::vector<int>)':
paint.cpp:33:36: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 | #define rep(i, n) for (ll i = 0; i < n; i++)
......
   57 |   rep(i, l.size()) {
      |       ~~~~~~~~~~~                   
paint.cpp:57:3: note: in expansion of macro 'rep'
   57 |   rep(i, l.size()) {
      |   ^~~
paint.cpp:33:36: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 | #define rep(i, n) for (ll i = 0; i < n; i++)
......
   62 |   rep(i, s.size()) {
      |       ~~~~~~~~~~~                   
paint.cpp:62:3: note: in expansion of macro 'rep'
   62 |   rep(i, s.size()) {
      |   ^~~
paint.cpp:33:36: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 | #define rep(i, n) for (ll i = 0; i < n; i++)
......
   87 |   rep(i, l.size()) {
      |       ~~~~~~~~~~~                   
paint.cpp:87:3: note: in expansion of macro 'rep'
   87 |   rep(i, l.size()) {
      |   ^~~
paint.cpp:33:36: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 | #define rep(i, n) for (ll i = 0; i < n; i++)
......
  103 |   rep(i, res.size()) {
      |       ~~~~~~~~~~~~~                 
paint.cpp:103:3: note: in expansion of macro 'rep'
  103 |   rep(i, res.size()) {
      |   ^~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...