답안 #660313

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660313 2022-11-21T15:11:14 Z 600Mihnea Building Skyscrapers (CEOI19_skyscrapers) C++17
8 / 100
3500 ms 6904 KB
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

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);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB ans=YES N=1
2 Correct 0 ms 212 KB ans=YES N=4
3 Correct 0 ms 212 KB ans=NO N=4
4 Correct 1 ms 340 KB ans=YES N=5
5 Correct 1 ms 340 KB ans=YES N=9
6 Correct 1 ms 212 KB ans=YES N=5
7 Correct 0 ms 340 KB ans=NO N=9
8 Correct 0 ms 340 KB ans=NO N=10
9 Correct 1 ms 340 KB ans=YES N=10
10 Correct 1 ms 212 KB ans=YES N=10
11 Correct 1 ms 340 KB ans=YES N=10
12 Correct 1 ms 340 KB ans=YES N=9
13 Correct 1 ms 340 KB ans=YES N=9
14 Correct 1 ms 212 KB ans=YES N=8
15 Correct 0 ms 340 KB ans=YES N=8
16 Correct 1 ms 212 KB ans=NO N=2
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB ans=YES N=1
2 Correct 0 ms 212 KB ans=YES N=4
3 Correct 0 ms 212 KB ans=NO N=4
4 Correct 1 ms 340 KB ans=YES N=5
5 Correct 1 ms 340 KB ans=YES N=9
6 Correct 1 ms 212 KB ans=YES N=5
7 Correct 0 ms 340 KB ans=NO N=9
8 Correct 0 ms 340 KB ans=NO N=10
9 Correct 1 ms 340 KB ans=YES N=10
10 Correct 1 ms 212 KB ans=YES N=10
11 Correct 1 ms 340 KB ans=YES N=10
12 Correct 1 ms 340 KB ans=YES N=9
13 Correct 1 ms 340 KB ans=YES N=9
14 Correct 1 ms 212 KB ans=YES N=8
15 Correct 0 ms 340 KB ans=YES N=8
16 Correct 1 ms 212 KB ans=NO N=2
17 Correct 1 ms 212 KB ans=YES N=17
18 Correct 1 ms 212 KB ans=YES N=25
19 Correct 5 ms 340 KB ans=YES N=100
20 Correct 9 ms 340 KB ans=YES N=185
21 Correct 0 ms 340 KB ans=NO N=174
22 Correct 4 ms 344 KB ans=YES N=90
23 Correct 2 ms 212 KB ans=YES N=63
24 Correct 3 ms 348 KB ans=YES N=87
25 Correct 9 ms 356 KB ans=YES N=183
26 Correct 10 ms 340 KB ans=YES N=188
27 Incorrect 9 ms 340 KB Added cell 147 (-529426737,-391881217) not reachable from infinity
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB ans=YES N=1
2 Correct 0 ms 212 KB ans=YES N=4
3 Correct 0 ms 212 KB ans=NO N=4
4 Correct 1 ms 340 KB ans=YES N=5
5 Correct 1 ms 340 KB ans=YES N=9
6 Correct 1 ms 212 KB ans=YES N=5
7 Correct 0 ms 340 KB ans=NO N=9
8 Correct 0 ms 340 KB ans=NO N=10
9 Correct 1 ms 340 KB ans=YES N=10
10 Correct 1 ms 212 KB ans=YES N=10
11 Correct 1 ms 340 KB ans=YES N=10
12 Correct 1 ms 340 KB ans=YES N=9
13 Correct 1 ms 340 KB ans=YES N=9
14 Correct 1 ms 212 KB ans=YES N=8
15 Correct 0 ms 340 KB ans=YES N=8
16 Correct 1 ms 212 KB ans=NO N=2
17 Correct 1 ms 212 KB ans=YES N=17
18 Correct 1 ms 212 KB ans=YES N=25
19 Correct 5 ms 340 KB ans=YES N=100
20 Correct 9 ms 340 KB ans=YES N=185
21 Correct 0 ms 340 KB ans=NO N=174
22 Correct 4 ms 344 KB ans=YES N=90
23 Correct 2 ms 212 KB ans=YES N=63
24 Correct 3 ms 348 KB ans=YES N=87
25 Correct 9 ms 356 KB ans=YES N=183
26 Correct 10 ms 340 KB ans=YES N=188
27 Incorrect 9 ms 340 KB Added cell 147 (-529426737,-391881217) not reachable from infinity
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB ans=NO N=1934
2 Correct 1 ms 468 KB ans=NO N=1965
3 Incorrect 143 ms 488 KB Contestant's solution is not lexicographically largest at index 1824 (1813 vs 1063)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB ans=YES N=1
2 Correct 0 ms 212 KB ans=YES N=4
3 Correct 0 ms 212 KB ans=NO N=4
4 Correct 1 ms 340 KB ans=YES N=5
5 Correct 1 ms 340 KB ans=YES N=9
6 Correct 1 ms 212 KB ans=YES N=5
7 Correct 0 ms 340 KB ans=NO N=9
8 Correct 0 ms 340 KB ans=NO N=10
9 Correct 1 ms 340 KB ans=YES N=10
10 Correct 1 ms 212 KB ans=YES N=10
11 Correct 1 ms 340 KB ans=YES N=10
12 Correct 1 ms 340 KB ans=YES N=9
13 Correct 1 ms 340 KB ans=YES N=9
14 Correct 1 ms 212 KB ans=YES N=8
15 Correct 0 ms 340 KB ans=YES N=8
16 Correct 1 ms 212 KB ans=NO N=2
17 Correct 1 ms 212 KB ans=YES N=17
18 Correct 1 ms 212 KB ans=YES N=25
19 Correct 5 ms 340 KB ans=YES N=100
20 Correct 9 ms 340 KB ans=YES N=185
21 Correct 0 ms 340 KB ans=NO N=174
22 Correct 4 ms 344 KB ans=YES N=90
23 Correct 2 ms 212 KB ans=YES N=63
24 Correct 3 ms 348 KB ans=YES N=87
25 Correct 9 ms 356 KB ans=YES N=183
26 Correct 10 ms 340 KB ans=YES N=188
27 Incorrect 9 ms 340 KB Added cell 147 (-529426737,-391881217) not reachable from infinity
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 5824 KB ans=NO N=66151
2 Correct 26 ms 4996 KB ans=NO N=64333
3 Execution timed out 3559 ms 6904 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB ans=NO N=1934
2 Correct 1 ms 468 KB ans=NO N=1965
3 Incorrect 143 ms 488 KB Contestant's solution is not lexicographically largest at index 1824 (1813 vs 1063)
4 Halted 0 ms 0 KB -