Submission #660313

#TimeUsernameProblemLanguageResultExecution timeMemory
660313600MihneaBuilding Skyscrapers (CEOI19_skyscrapers)C++17
8 / 100
3559 ms6904 KiB
bool home = 0; #include <bits/stdc++.h> using namespace std; struct T { int x; int y; }; bool operator < (T a, T b) { if (a.x != b.x) { return a.x < b.x; } return a.y < b.y; } mt19937 rng(777); const int N = 150000 + 7; int n; int task; T points[N]; int d[N]; map<T, int> w; int main() { if (home == 0) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } else { freopen ("input.txt", "r", stdin); } cin >> n >> task; assert(task == 1 || task == 2); for (int i = 1; i <= n; i++) { cin >> points[i].x >> points[i].y; w[points[i]] = i; } vector<int> samples; for (int i = 1; i <= 100; i++) { samples.push_back(rng() % n + 1); } vector<int> sol; int best = (int) 1e9 + 7; for (auto &root : samples) { for (int i = 1; i <= n; i++) { d[i] = -1; } vector<int> ord; queue<int> q; q.push(root); d[root] = 0; while (!q.empty()) { int a = q.front(); ord.push_back(a); q.pop(); for (int dx = -1; dx <= +1; dx++) { for (int dy = -1; dy <= +1; dy++) { T nw = {points[a].x + dx, points[a].y + dy}; if (w.count(nw)) { int j = w[nw]; if (d[j] == -1) { d[j] = 1 + d[a]; q.push(j); } } } } } if ((int) ord.size() != n) { cout << "NO\n"; return 0; } int cur = *max_element(d + 1, d + n + 1); if (cur < best) { best = cur; sol = ord; } } cout << "YES\n"; for (auto &v : sol) { cout << v << "\n"; } return 0; }

Compilation message (stderr)

skyscrapers.cpp: In function 'int main()':
skyscrapers.cpp:38:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen ("input.txt", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...