제출 #564641

#제출 시각아이디문제언어결과실행 시간메모리
5646411zaid1Building Skyscrapers (CEOI19_skyscrapers)C++14
0 / 100
130 ms58152 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define int long long typedef long long ll; const int M = 2e6 + 5, MOD = 1e9+7; struct point {int x, y, i;}; vector<int> node[M]; int vis[M], cnt; vector<int> ans; void dfs(int s) { vis[s] = true; ans.push_back(s); cnt++; int mx = 0, tmp = 0; for (int i:node[s]) mx += vis[i]; if (mx >= 2) { swap(ans[ans.size()-1], ans[ans.size()-2]); tmp = ans.back(); ans.pop_back(); } for (int i:node[s]) { if (!vis[i]) dfs(i); } if (tmp) ans.push_back(tmp); } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); srand(time(0)); int n, t; cin >> n >> t; vector<point> v(n); for (auto&i:v) cin >> i.x >> i.y; int ind = 1; for (auto&i:v) i.i = ind++; vector<point> p; sort(v.begin(), v.end(), [](point a, point b){if (a.y == b.y) return a.x < b.x; return a.y < b.y;}); int ii = n, lst = v.back().y; while (--ii >= 0) { if (v[ii].y != lst) { for (int j = 1; j < p.size(); j++) { if (p[j-1].x == p[j].x+1) { node[p[j].i].push_back(p[j-1].i); node[p[j-1].i].push_back(p[j].i); } } p.clear(); } p.push_back(v[ii]); lst = v[ii].y; } for (int j = 1; j < p.size(); j++) { if (p[j-1].x+1 == p[j].x) { node[p[j].i].push_back(p[j-1].i); node[p[j-1].i].push_back(p[j].i); } } p.clear(); p.clear(); sort(v.begin(), v.end(), [](point a, point b){if (a.x == b.x) return a.y < b.y; return a.x < b.x;}); ii = n, lst = v.back().x; while (--ii >= 0) { if (v[ii].x != lst) { for (int j = 1; j < p.size(); j++) { if (p[j-1].y == p[j].y+1) { node[p[j].i].push_back(p[j-1].i); node[p[j-1].i].push_back(p[j].i); } } p.clear(); } p.push_back(v[ii]); lst = v[ii].x; } for (int j = 1; j < p.size(); j++) { if (p[j-1].y+1 == p[j].y) { node[p[j].i].push_back(p[j-1].i); node[p[j-1].i].push_back(p[j].i); } } p.clear(); sort(v.begin(), v.end(), [](point a, point b){if ((a.x+a.y) == (b.x+b.y)) return a.x < b.x; return a.x+a.y < b.x+b.y;}); ii = n, lst = (v.back().x+v.back().y); while (--ii >= 0) { if (v[ii].x+v[ii].y != lst) { for (int j = 1; j < p.size(); j++) { if (p[j-1].x == p[j].x+1) { node[p[j].i].push_back(p[j-1].i); node[p[j-1].i].push_back(p[j].i); } } p.clear(); } p.push_back(v[ii]); lst = v[ii].x+v[ii].y; } for (int j = 1; j < p.size(); j++) { if (p[j-1].x+1 == p[j].x) { node[p[j].i].push_back(p[j-1].i); node[p[j-1].i].push_back(p[j].i); } } p.clear(); sort(v.begin(), v.end(), [](point a, point b){if ((a.x-a.y) == (b.x-b.y)) return a.x < b.x; return a.x-a.y < b.x-b.y;}); ii = n, lst = (v.back().x-v.back().y); while (--ii >= 0) { if (v[ii].x-v[ii].y != lst) { for (int j = 1; j < p.size(); j++) { if (p[j-1].x == p[j].x+1) { node[p[j].i].push_back(p[j-1].i); node[p[j-1].i].push_back(p[j].i); } } p.clear(); } p.push_back(v[ii]); lst = v[ii].x-v[ii].y; } for (int j = 1; j < p.size(); j++) { if (p[j-1].x+1 == p[j].x) { node[p[j].i].push_back(p[j-1].i); node[p[j-1].i].push_back(p[j].i); } } p.clear(); dfs(1); if (cnt >= n) { cout << "YES" << endl; for (int i:ans) cout << i << endl; } else cout << "NO"<< endl; return 0; } /* 3 2 0 0 0 1 0 2 4 1 -1 1 1 1 -1 -1 1 -1 */

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

skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:47:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |             for (int j = 1; j < p.size(); j++) {
      |                             ~~^~~~~~~~~~
skyscrapers.cpp:59:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (int j = 1; j < p.size(); j++) {
      |                     ~~^~~~~~~~~~
skyscrapers.cpp:71:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |             for (int j = 1; j < p.size(); j++) {
      |                             ~~^~~~~~~~~~
skyscrapers.cpp:83:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for (int j = 1; j < p.size(); j++) {
      |                     ~~^~~~~~~~~~
skyscrapers.cpp:94:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |             for (int j = 1; j < p.size(); j++) {
      |                             ~~^~~~~~~~~~
skyscrapers.cpp:106:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |     for (int j = 1; j < p.size(); j++) {
      |                     ~~^~~~~~~~~~
skyscrapers.cpp:117:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |             for (int j = 1; j < p.size(); j++) {
      |                             ~~^~~~~~~~~~
skyscrapers.cpp:129:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |     for (int j = 1; j < p.size(); j++) {
      |                     ~~^~~~~~~~~~
#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...