Submission #1302335

#TimeUsernameProblemLanguageResultExecution timeMemory
1302335skibidigodv9Towers (NOI22_towers)C++20
23 / 100
207 ms51252 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=(a),_##i=(b);i<_##i;++i)
#define foru(i,a,b) for(int i=(a),_##i=(b);i<=_##i;++i)
#define ford(i,a,b) for(int i=(a),_##i=(b);i>=_##i;--i)
#define r0p(i,b) for(int i=0,_##i=(b);i<_##i;++i)
#define fileio(TASK) if (fopen(TASK".INP","r")) {\
  freopen(TASK".INP","r",stdin); freopen(TASK".OUT","w",stdout); }
template<typename T, typename S> bool mini(T &x, const S &y) {
  return x > y ? x = y, true : false; }
template<typename T, typename S> bool maxi(T &x, const S &y) {
  return x < y ? x = y, true : false; }

const int max_n = 1000011;
int n;
struct Point {
  int x, y, id;
  void input(int i) {
    cin >> x >> y;
    id = i;
  }
  inline void flip() {
    swap(x, y);
  }
  bool operator<(const Point &ot) const {
    return x < ot.x || (x == ot.x && y < ot.y);
  }
} point[max_n];

void input() {
  cin >> n;
  r0p (i, n) {
    point[i].input(i);
  }
}

namespace sub2 {
  bool valid() {
    return n <= 16;
  }
  void process() {
#ifdef ON_LOCAL
    cerr << "> Running subtask 1-2" << endl;
#endif
    const int SUPER_MASK = (1 << n) - 1;
    vector<int> set_x(max_n, 0), set_y(max_n, 0);
    foru (msk, 1, SUPER_MASK) {
      bool all_light = true;
      for (int um = SUPER_MASK ^ msk; um > 0; um -= um & -um) {
        int i = __builtin_ctz(um);
        int cntx[2] = {0, 0}, cnty[2] = {0, 0};
        for (int m = msk; m > 0; m -= m & -m) {
          int j = __builtin_ctz(m);
          if (point[j].y == point[i].y) ++cntx[point[j].x >= point[i].x];
          if (point[j].x == point[i].x) ++cnty[point[j].y >= point[i].y];
        }
        if ((cntx[0] > 0 && cntx[1] > 0) || (cnty[0] > 0 && cnty[1] > 0))
          continue;
        all_light = false;
        break;
      }
      bool too_many = false;
      for (int m = msk; m > 0; m -= m & -m) {
        int i = __builtin_ctz(m);
        ++set_x[point[i].x];
        ++set_y[point[i].y];
        too_many = too_many || (set_x[point[i].x] > 2 || set_y[point[i].y] > 2);
      }
      if (!too_many && all_light) {
#ifdef ON_LOCAL
        cerr << "> Found answer" << endl;
#endif
        r0p (i, n)
          cout << (msk >> i & 1);
        cout << '\n';
        return;
      }
      for (int m = msk; m > 0; m -= m & -m) {
        int i = __builtin_ctz(m);
        --set_x[point[i].x];
        --set_y[point[i].y];
      }
    }
  }
}

namespace sub3 {
  bool valid() {
    unordered_map<int, int> mp;
    r0p (i, n) {
      ++mp[point[i].x];
      if (mp[point[i].x] > 2)
        return false;
    }
    return true;
  }
  void process() {
#ifdef ON_LOCAL
    cerr << "> Running subtask 3" << endl;
#endif
    r0p (i, n)
      cout << '1';
    cout << '\n';
  }
}

namespace sub6 {
  bool valid() {
    return true;
  }
  vector<int> set_x, set_y;
  vector<bool> put_light;

  void process_light(vector<int> &group) {
    if (set_x[point[group[0]].x] == 2) return;
    int sz = group.size();
    int first = -1;
    r0p (i, sz) {
      int id = group[i];
      if (!put_light[point[id].id] && set_y[point[id].y] < 2) {
        put_light[point[id].id] = true;
        first = point[id].id;
        ++set_x[point[id].x];
        ++set_y[point[id].y];
        break;
      }
    }
    ford (i, sz - 1, 0) {
      int id = group[i];
      if (!put_light[point[id].id] && set_y[point[id].y] < 2 && set_x[point[id].x] + (point[id].id != first) <= 2) {
        put_light[point[id].id] = true;
        ++set_x[point[id].x];
        ++set_y[point[id].y];
        break;
      }
    }
  }

  void solve() {
    sort(point, point + n);
    vector<vector<int>> group;
    r0p (i, n) {
      if (group.empty() || point[group.back().front()].x != point[i].x)
        group.emplace_back();
      group.back().pb(i);
    }
    int left_ptr = 0, right_ptr = group.size() - 1;
    while (left_ptr < right_ptr) {
      process_light(group[left_ptr]);
      ++left_ptr;
      if (left_ptr < right_ptr) {
        process_light(group[right_ptr]);
        --right_ptr;
      }
    }
    if (left_ptr == right_ptr)
      process_light(group[left_ptr]);
  }

  void process() {
#ifdef ON_LOCAL
    cerr << "> Running subtask 4-5-6" << endl;
#endif
    set_x.assign(max_n, 0);
    set_y.assign(max_n, 0);
    put_light.assign(n, false);
    solve();
    r0p (i, n) point[i].flip();
    set_x.swap(set_y);
    solve();
    r0p (i, n)
      cout << (put_light[i] ? 1 : 0);
    cout << '\n';
  }
}

void preprocess() {
  if (sub2::valid()) {
    sub2::process();
    return;
  }
  if (sub3::valid()) {
    sub3::process();
    return;
  }
  if (sub6::valid()) {
    sub6::process();
    return;
  }
}

int main() {
  fileio("SLAMP")
  cin.tie(nullptr)->sync_with_stdio(false);
  input();
  preprocess();
  return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:15:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   freopen(TASK".INP","r",stdin); freopen(TASK".OUT","w",stdout); }
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:200:3: note: in expansion of macro 'fileio'
  200 |   fileio("SLAMP")
      |   ^~~~~~
Main.cpp:15:41: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   freopen(TASK".INP","r",stdin); freopen(TASK".OUT","w",stdout); }
      |                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:200:3: note: in expansion of macro 'fileio'
  200 |   fileio("SLAMP")
      |   ^~~~~~
#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...