Submission #1482035
Source Code Expand
#include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> // c++11 #include <array> #include <tuple> #include <unordered_map> #include <unordered_set> #define mp make_pair #define mt make_tuple #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; const int INF = 1 << 29; const double EPS = 1e-9; const ll MOD = 1000000007; const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; const int MAX_N = 110; int N; int deg[MAX_N]; vector<int> A; bool ok; bool check() { for (int i = 0; i < MAX_N; i++) { if (deg[i] > 0) { return false; } } return true; } int main() { ok = true; cin >> N; A.resize(N); for (auto &val : A) { cin >> val; deg[val]++; } sort(A.rbegin(), A.rend()); int max_val = A[0]; int min_val = A[N - 1]; if (max_val % 2) { int res = max_val; for (int i = 0; i <= max_val / 2; i++) { deg[res] -= 2; if (deg[res] < 0) { ok = false; goto END; } res--; } int left = max_val - ((max_val / 2) - 1); int right = max_val; for (int i = 0; i < MAX_N; i++){ if (deg[i] > 0){ if (not (left <= i and i <= right)){ ok = false; goto END; } deg[i] = 0; } } } else { int res = max_val; for (int i = 0; i < max_val / 2; i++) { deg[res] -= 2; if (deg[res] < 0) { ok = false; goto END; } res--; } deg[res]--; int left = max_val - ((max_val / 2) - 1); int right = max_val; for (int i = 0; i < MAX_N; i++){ if (deg[i] > 0){ if (not (left <= i and i <= right)){ ok = false; goto END; } deg[i] = 0; } } } END:; ok &= check(); if (ok){ cout << "Possible" << endl; }else{ cout << "Impossible" << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Tree Restoring |
User | togatoga |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 2473 Byte |
Status | AC |
Exec Time | 1 ms |
Memory | 256 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0, example1, example2, example3, example4, example5 |
All | almostline0, almostline1, almostline2, almostline3, can0, can1, can2, can3, can4, can5, can6, deg0, deg1, deg2, deg3, example0, example1, example2, example3, example4, example5, handmade0, line0, line1, line2, line3, ng10, ng11, ng12, ng13, ng20, ng21, ng22, ng23, plus0, plus1, plus2, plus3, rand0, rand1, rand2, star0, star1, star2, star3 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
almostline0 | AC | 1 ms | 256 KB |
almostline1 | AC | 1 ms | 256 KB |
almostline2 | AC | 1 ms | 256 KB |
almostline3 | AC | 1 ms | 256 KB |
can0 | AC | 1 ms | 256 KB |
can1 | AC | 1 ms | 256 KB |
can2 | AC | 1 ms | 256 KB |
can3 | AC | 1 ms | 256 KB |
can4 | AC | 1 ms | 256 KB |
can5 | AC | 1 ms | 256 KB |
can6 | AC | 1 ms | 256 KB |
deg0 | AC | 1 ms | 256 KB |
deg1 | AC | 1 ms | 256 KB |
deg2 | AC | 1 ms | 256 KB |
deg3 | AC | 1 ms | 256 KB |
example0 | AC | 1 ms | 256 KB |
example1 | AC | 1 ms | 256 KB |
example2 | AC | 1 ms | 256 KB |
example3 | AC | 1 ms | 256 KB |
example4 | AC | 1 ms | 256 KB |
example5 | AC | 1 ms | 256 KB |
handmade0 | AC | 1 ms | 256 KB |
line0 | AC | 1 ms | 256 KB |
line1 | AC | 1 ms | 256 KB |
line2 | AC | 1 ms | 256 KB |
line3 | AC | 1 ms | 256 KB |
ng10 | AC | 1 ms | 256 KB |
ng11 | AC | 1 ms | 256 KB |
ng12 | AC | 1 ms | 256 KB |
ng13 | AC | 1 ms | 256 KB |
ng20 | AC | 1 ms | 256 KB |
ng21 | AC | 1 ms | 256 KB |
ng22 | AC | 1 ms | 256 KB |
ng23 | AC | 1 ms | 256 KB |
plus0 | AC | 1 ms | 256 KB |
plus1 | AC | 1 ms | 256 KB |
plus2 | AC | 1 ms | 256 KB |
plus3 | AC | 1 ms | 256 KB |
rand0 | AC | 1 ms | 256 KB |
rand1 | AC | 1 ms | 256 KB |
rand2 | AC | 1 ms | 256 KB |
star0 | AC | 1 ms | 256 KB |
star1 | AC | 1 ms | 256 KB |
star2 | AC | 1 ms | 256 KB |
star3 | AC | 1 ms | 256 KB |