Submission #17081716
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T, class U>
void chmin(T& t, const U& u) {
if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
if (t < u) t = u;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "{";
rep(i, v.size()) {
if (i) os << ",";
os << v[i];
}
os << "}";
return os;
}
#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << H;
debug_out(T...);
}
#define debug(...) \
cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
int main() {
int N;
cin >> N;
V<int> A(N), B(N);
int sz = N * 2;
V<int> tp(sz), com(sz, -1);
bool ng = false;
rep(i, N) {
cin >> A[i] >> B[i];
if (A[i] != -1) {
--A[i];
if (tp[A[i]]) ng = true;
tp[A[i]] = i + 1;
}
if (B[i] != -1) {
--B[i];
if (tp[B[i]]) ng = true;
tp[B[i]] = -(i + 1);
}
if (A[i] != -1 && B[i] != -1) {
com[A[i]] = B[i];
com[B[i]] = A[i];
}
}
if (ng) {
puts("No");
return 0;
}
V<bool> dp(sz + 1);
dp[0] = true;
rep(i, sz) {
if (!dp[i]) continue;
for (int j = i + 1; j < sz; ++j) {
int w = j - i + 1;
if (w & 1) continue;
w /= 2;
bool ok = true;
V<bool> exist(N);
rep(k, w) {
int p = i + k, q = i + k + w;
if (com[p] != -1 && !(i <= com[p] && com[p] <= j)) {
ok = false;
}
if (com[q] != -1 && !(i <= com[q] && com[q] <= j)) {
ok = false;
}
bool same = true;
if (tp[p] != 0 && tp[q] != 0) {
if (tp[p] < 0 || tp[p] + tp[q] != 0) {
ok = false;
} else
same = true;
}
if (tp[p] < 0 || tp[q] > 0) {
ok = false;
} else {
if (tp[p] != 0) {
int v = tp[p] - 1;
if (exist[v]) {
ok = false;
}
exist[v] = true;
}
if (!same && tp[q] != 0) {
int v = -tp[q] - 1;
if (exist[v]) {
ok = false;
}
exist[v] = true;
}
}
}
if (ok) {
dp[j + 1] = true;
}
}
}
puts(dp[sz] ? "Yes" : "No");
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Fair Elevator |
| User | satashun |
| Language | C++ (GCC 9.2.1) |
| Score | 600 |
| Code Size | 3907 Byte |
| Status | AC |
| Exec Time | 8 ms |
| Memory | 3556 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 600 / 600 | ||||
| Status |
|
|
| 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 | 8 ms | 3480 KiB |
| 02.txt | AC | 2 ms | 3548 KiB |
| 03.txt | AC | 2 ms | 3472 KiB |
| 04.txt | AC | 2 ms | 3440 KiB |
| 05.txt | AC | 4 ms | 3556 KiB |
| 06.txt | AC | 2 ms | 3380 KiB |
| 07.txt | AC | 8 ms | 3380 KiB |
| 08.txt | AC | 4 ms | 3480 KiB |
| 09.txt | AC | 4 ms | 3436 KiB |
| 10.txt | AC | 4 ms | 3372 KiB |
| 11.txt | AC | 4 ms | 3440 KiB |
| 12.txt | AC | 4 ms | 3500 KiB |
| 13.txt | AC | 2 ms | 3476 KiB |
| 14.txt | AC | 4 ms | 3444 KiB |
| 15.txt | AC | 4 ms | 3480 KiB |
| 16.txt | AC | 2 ms | 3436 KiB |
| 17.txt | AC | 3 ms | 3440 KiB |
| 18.txt | AC | 3 ms | 3436 KiB |
| 19.txt | AC | 4 ms | 3500 KiB |
| 20.txt | AC | 4 ms | 3448 KiB |
| 21.txt | AC | 2 ms | 3424 KiB |
| 22.txt | AC | 2 ms | 3428 KiB |
| 23.txt | AC | 3 ms | 3552 KiB |
| 24.txt | AC | 3 ms | 3380 KiB |
| 25.txt | AC | 2 ms | 3552 KiB |
| 26.txt | AC | 4 ms | 3500 KiB |
| 27.txt | AC | 2 ms | 3432 KiB |
| 28.txt | AC | 5 ms | 3484 KiB |
| 29.txt | AC | 3 ms | 3504 KiB |
| 30.txt | AC | 2 ms | 3500 KiB |
| 31.txt | AC | 2 ms | 3440 KiB |
| 32.txt | AC | 5 ms | 3484 KiB |
| 33.txt | AC | 2 ms | 3500 KiB |
| 34.txt | AC | 5 ms | 3484 KiB |
| 35.txt | AC | 2 ms | 3484 KiB |
| 36.txt | AC | 2 ms | 3452 KiB |
| 37.txt | AC | 4 ms | 3484 KiB |
| 38.txt | AC | 2 ms | 3484 KiB |
| 39.txt | AC | 2 ms | 3444 KiB |
| 40.txt | AC | 3 ms | 3480 KiB |
| 41.txt | AC | 2 ms | 3448 KiB |
| 42.txt | AC | 3 ms | 3548 KiB |
| 43.txt | AC | 2 ms | 3556 KiB |
| s1.txt | AC | 1 ms | 3476 KiB |
| s2.txt | AC | 2 ms | 3548 KiB |
| s3.txt | AC | 2 ms | 3476 KiB |