# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
740073 | 2023-05-12T05:15:47 Z | vjudge1 | 분수 공원 (IOI21_parks) | C++17 | 0 ms | 0 KB |
#include "parks.h" #include <bits/stdc++.h> using namespace std; static void check(bool cond, string message) { if (!cond) { printf("%s\n", message.c_str()); fclose(stdout); exit(0); } } static int n; static bool build_called; static int m; static vector<int> _u, _v, _a, _b; void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b) { check(!build_called, "build is called more than once"); build_called = true; m = u.size(); check(int(v.size()) == m, "u.size() != v.size()"); check(int(a.size()) == m, "u.size() != a.size()"); check(int(b.size()) == m, "u.size() != b.size()"); _u = u; _v = v; _a = a; _b = b; } const int maxn = 2e5 + 100; int ord[maxn]; vector<int>x, y; int construct_roads() { if (x.size() == 1) { build({}, {}, {}, {}); return 1; } for(int i=0; i<n; i++){ ord[i] = i; } sort(ord, ord+n, [](int a, int b){ return y[a] < y[b]; }); bool ok = 1; vector<int>u, v, a, b; for(int i=1; i<n; i++){ if(y[i]-y[i-1] != 2) ok = 0; u.push_back(ord[i-1]); v.push_back(ord[i]); a.push_back(1); b.push_back(y[ord[i]]-1); } if(ok) build(u, v, a, b); return ok; } int main() { assert(scanf("%d", &n) == 1); x.resize(n); y.resize(n); for (int i = 0; i < n; i++) { assert(scanf("%d%d", &x[i], &y[i]) == 2); } fclose(stdin); build_called = false; const int possible = construct_roads(); check(possible == 0 || possible == 1, "Invalid return value of construct_roads()"); if (possible == 1) { check(build_called, "construct_roads() returned 1 without calling build()"); } else { check(!build_called, "construct_roads() called build() but returned 0"); } printf("%d\n", possible); if (possible == 1) { printf("%d\n", m); for (int j = 0; j < m; j++) { printf("%d %d %d %d\n", _u[j], _v[j], _a[j], _b[j]); } } fclose(stdout); return 0; }