제출 #1302468

#제출 시각아이디문제언어결과실행 시간메모리
1302468duyanhloveavTowers (NOI22_towers)C++20
22 / 100
490 ms39568 KiB
#include<bits/stdc++.h>
using namespace std;

using ll = long long;

const int mxn = 9 + 1e6;
const int inf = 0x3f3f3f3f;
const ll lnf = 0x3f3f3f3f3f3f3f3f;

int n;
vector<array<int, 2>> light;

namespace SUB12 {
  bool check() {
    return (n <= 16);
  }

  void solve() {
    vector<int> mx_x(mxn, 0), mx_y(mxn, 0), mn_x(mxn, inf), mn_y(mxn, inf);
    vector<int> cnt_x(mxn, 0), cnt_y(mxn, 0);
    for (int msk = 0; msk < (1 << n); ++msk) {
      bool f = true;
      for (int i = 0; i < n; ++i) {
        if (msk >> i & 1) {
          mx_x[light[i][1]] = max(mx_x[light[i][1]], light[i][0]);
          mn_x[light[i][1]] = min(mn_x[light[i][1]], light[i][0]);
          mx_y[light[i][0]] = max(mx_y[light[i][0]], light[i][1]);
          mn_y[light[i][0]] = min(mn_y[light[i][0]], light[i][1]);
          if ((++cnt_x[light[i][0]]) > 2) {
            f = false;
            break;
          }
          if ((++cnt_y[light[i][1]]) > 2) {
            f = false;
            break;
          }
        }
      }
      if (!f) {
        for (int i = 0; i < n; ++i) {
          if (msk >> i & 1) {
            mx_x[light[i][1]] = 0;
            mn_x[light[i][1]] = inf;
            mx_y[light[i][0]] = 0;
            mn_y[light[i][0]] = inf;
            cnt_x[light[i][0]] = 0;
            cnt_y[light[i][1]] = 0;
          }
        }
        continue;
      }
      f = true;
      for (int i = 0; i < n; ++i) {
        if (!(mn_x[light[i][1]] <= light[i][0] && light[i][0] <= mx_x[light[i][1]]) && !(mn_y[light[i][0]] <= light[i][1] && light[i][1] <= mx_y[light[i][0]])) {
          f = false;
          break;
        }
      }
      if (f) {
        for (int i = 0; i < n; ++i) {
          if (msk >> i & 1) {
            cout << 1;
          } else {
            cout << 0;
          }
        }
        cout << "\n";
        return;
      }
      for (int i = 0; i < n; ++i) {
        if (msk >> i & 1) {
          mx_x[light[i][1]] = 0;
          mn_x[light[i][1]] = inf;
          mx_y[light[i][0]] = 0;
          mn_y[light[i][0]] = inf;
          cnt_x[light[i][0]] = 0;
          cnt_y[light[i][1]] = 0;
        }
      }
    }
  }
}

namespace SUB3 {
  bool check() {
    vector<int> cnt(mxn);
    for (int i = 0; i < n; ++i) {
      if ((++cnt[light[i][0]]) > 2) {
        return false;
      }
    }
    return true;
  }

  void solve() {
    vector<int> mn_x(mxn, inf), mx_x(mxn, 0), posmn_x(mxn), posmx_x(mxn);
    for (int i = 0; i < n; ++i) {
      if (mn_x[light[i][1]] > light[i][0]) {
        mn_x[light[i][1]] = light[i][0];
        posmn_x[light[i][1]] = i;
      }
      if (mx_x[light[i][1]] < light[i][0]) {
        mx_x[light[i][1]] = light[i][0];
        posmx_x[light[i][1]] = i;
      }
    }
    vector<bool> used(n + 1);
    for (int i = 1; i < mxn; ++i) {
      if (mn_x[i] == inf) {
        continue;
      }
      used[posmn_x[i]] = used[posmx_x[i]] = true;
    }
    for (int i = 0; i < n; ++i) {
      cout << used[i];
    }
  }
}

void _27augain(void) {
  cin >> n;
  light.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> light[i][0] >> light[i][1];
  }
  if (SUB12::check()) {
    SUB12::solve();
    return;
  }
  SUB3::solve();
}

int32_t main() {
#define TASK "SLAMP"
  if (fopen(TASK ".inp", "r")) {
    freopen(TASK ".inp", "r", stdin);
    freopen(TASK ".out", "w", stdout);
  }
  int testcase = 1;
//  cin >> testcase;
  while (testcase--) {
    _27augain();
  }
  return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int32_t main()':
Main.cpp:136:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  136 |     freopen(TASK ".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:137:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  137 |     freopen(TASK ".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...