Submission #17176000


Source Code Expand

Copy
// #define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

bool inside(int x, int L, int R) {
  return x >= L && x <= R;
}

int main() {
  int n, m = 0;
  cin >> n;
  vector<int> a(n), b(n);
  vector<bool> visit(n * 2 + 1);
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  while (true) {
    bool over = true;
    for (int i = 0; i < n; ++i) {
      if (a[i] == -1 ||  b[i] == -1) continue;
      int len = b[i] - a[i];
      for (int j = 0; j < n; ++j) {
        if (inside(a[j], a[i], b[i]) && b[j] == -1) b[j] = a[j] + len, over = false;
        if (inside(b[j], a[i], b[i]) && a[j] == -1) a[j] = b[j] - len, over = false;
      }
    }
    if (over) break;
  }
  bool found = false;
  for (int i = 0; i < n; ++i) {
    if (a[i] != -1 && b[i] != -1 && a[i] >= b[i]) found = true;
    if (a[i] != -1) {
      if (visit[a[i]]) found = true;
      visit[a[i]] = true;
    }
    if (b[i] != -1) {
      if (visit[b[i]]) found = true;
      visit[b[i]] = true;
    }
    if (a[i] == -1 && b[i] == -1) m++;
  }
  if (found) {
    cout << "No" << endl;
    return 0;
  }
  vector<bool> dp(2 * n + 1);
  dp[0] = true;
  for (int i = 2; i <= 2 * n; i += 2) {
    for (int k = 2; k <= i; k += 2) {
      if (!dp[i - k]) continue;
      // [i - k + 1, i]
      int j = i - k + 1;
      int len = (k + 2) / 2;
      bool found = false;
      int cnt = 0, cnt2 = 0;
      for (int u = 0; u < n; ++u) {
        if (a[u] != -1 && b[u] != -1) {
          bool cur = inside(a[u], j, i) || inside(b[u], j, i);
          cnt += cur;
          if (inside(a[u], j, i) ^ inside(b[u], j, i)) found = true;
          if (cur && b[u] - a[u] + 1 != len) found = true;
          if (a[u] < j && b[u] > i) found = true;
        } else if (a[u] != -1 && b[u] == -1) {
          cnt += inside(a[u], j, i) || inside(b[u], j, i);
          if (inside(a[u], j, i) && !inside(a[u] + len - 1, j, i)) found = true;
        } else if (a[u] == -1 && b[u] != -1) {
          cnt += inside(a[u], j, i) || inside(b[u], j, i);
          if (inside(b[u], j, i) && !inside(b[u] - len + 1, j, i)) found = true;
        } else {
          ++cnt2;
        }
      }
      trace(i, j, k, len, found, cnt);
      if (!found && cnt <= k / 2 && cnt + cnt2 >= k / 2) dp[i] = true;
    }
    trace(i, dp[i]);
  }
  cout << (dp[2 * n] ? "Yes" : "No") << endl;
  return 0;
}

Submission Info

Submission Time
Task C - Fair Elevator
User cuiaoxiang
Language C++ (Clang 10.0.0)
Score 0
Code Size 4840 Byte
Status RE
Exec Time 2205 ms
Memory 3116 KB

Compile Error

./Main.cpp:78:11: warning: unused variable 'INF' [-Wunused-const-variable]
const int INF = 1 << 29;
          ^
./Main.cpp:79:11: warning: unused variable 'MOD' [-Wunused-const-variable]
const int MOD = 1e9 + 7;
          ^
2 warnings generated.

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 3
AC × 38
TLE × 1
RE × 7
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 6 ms 3040 KB
02.txt AC 2 ms 3008 KB
03.txt AC 2 ms 3044 KB
04.txt AC 4 ms 3032 KB
05.txt AC 4 ms 2988 KB
06.txt AC 2 ms 2896 KB
07.txt AC 4 ms 3112 KB
08.txt AC 8 ms 3008 KB
09.txt AC 5 ms 3028 KB
10.txt AC 6 ms 3036 KB
11.txt AC 3 ms 3028 KB
12.txt AC 4 ms 3020 KB
13.txt AC 2 ms 3116 KB
14.txt AC 5 ms 3044 KB
15.txt AC 5 ms 2852 KB
16.txt AC 4 ms 3048 KB
17.txt AC 3 ms 3044 KB
18.txt AC 4 ms 2952 KB
19.txt AC 4 ms 3044 KB
20.txt AC 5 ms 3036 KB
21.txt AC 2 ms 3032 KB
22.txt AC 3 ms 2896 KB
23.txt AC 3 ms 3040 KB
24.txt RE 188 ms 2860 KB
25.txt RE 114 ms 2876 KB
26.txt AC 3 ms 3052 KB
27.txt RE 114 ms 2860 KB
28.txt AC 5 ms 3000 KB
29.txt AC 2 ms 3048 KB
30.txt RE 111 ms 2820 KB
31.txt TLE 2205 ms 2764 KB
32.txt AC 5 ms 3004 KB
33.txt AC 3 ms 3036 KB
34.txt RE 114 ms 2892 KB
35.txt RE 112 ms 2760 KB
36.txt RE 114 ms 2868 KB
37.txt AC 2 ms 2848 KB
38.txt AC 4 ms 2852 KB
39.txt AC 2 ms 2948 KB
40.txt AC 2 ms 2852 KB
41.txt AC 2 ms 2992 KB
42.txt AC 2 ms 3048 KB
43.txt AC 2 ms 2952 KB
s1.txt AC 2 ms 3036 KB
s2.txt AC 2 ms 3044 KB
s3.txt AC 2 ms 2852 KB