QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#660223#9427. Collect the CoinsliuziaoWA 29ms5684kbC++231.6kb2024-10-20 09:15:312024-10-20 09:15:32

Judging History

你现在查看的是最新测评结果

  • [2024-11-06 15:56:27]
  • hack成功,自动添加数据
  • (/hack/1139)
  • [2024-10-20 09:15:32]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:5684kb
  • [2024-10-20 09:15:31]
  • 提交

answer

#include <bits/stdc++.h>

// #define int int64_t

const int kMaxN = 1e6 + 5;

int n;
std::pair<int, int> a[kMaxN];

int getk(int i, int j) {
  if (i > j) std::swap(i, j);
  int d = a[j].first - a[i].first;
  if (a[i].first == a[j].first) return a[i].second == a[j].second ? 0 : 2e9;
  else return (abs(a[i].second - a[j].second) + d - 1) / d;
}

bool check(int v) {
  static bool vis[kMaxN];
  int id[2] = {0};
  std::vector<int> vec[2];
  for (int i = 2; i <= n; ++i) {
    vis[i] = 0;
    if (getk(i - 1, i) > v) vis[i] = 1;
  }
  int col = 0;
  vec[0].emplace_back(1);
  for (int i = 2; i <= n; ++i) {
    if (vis[i]) col ^= 1;
    vec[col].emplace_back(i);
  }
  for (int i = 1; i < (int)vec[0].size(); ++i)
    if (getk(vec[0][i - 1], vec[0][i]) > v)
      return 0;
  for (int i = 1; i < (int)vec[1].size(); ++i)
    if (getk(vec[1][i - 1], vec[1][i]) > v)
      return 0;
  return 1;
}

void dickdreamer() {
  std::cin >> n;
  for (int i = 1; i <= n; ++i) std::cin >> a[i].first >> a[i].second;
  std::sort(a + 1, a + 1 + n);
  int L = -1, R = 1e9 + 1, res = 1e9 + 1;
  while (L + 1 < R) {
    int mid = (L + R) >> 1;
    if (check(mid)) R = res = mid;
    else L = mid;
  }
  std::cout << (res == 1e9 + 1 ? -1 : res) << '\n';
}

int32_t main() {
#ifdef ORZXKR
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0);
  int T = 1;
  std::cin >> T;
  while (T--) dickdreamer();
  // std::cerr << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5684kb

input:

3
5
1 1
3 7
3 4
4 3
5 10
1
10 100
3
10 100
10 1000
10 10000

output:

2
0
-1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 29ms
memory: 3776kb

input:

1135
2
6 5
8 8
8
2 9
2 10
4 4
5 3
6 2
6 8
8 2
8 7
1
9 1
6
4 6
6 1
6 2
9 10
10 1
10 7
5
1 6
2 5
6 7
8 6
10 3
8
1 10
5 4
5 7
6 1
6 6
8 4
9 1
9 4
8
1 1
1 3
2 9
3 3
5 9
6 10
9 7
10 7
3
5 8
6 6
10 6
7
2 9
4 7
5 10
6 3
6 7
8 9
10 1
6
1 4
2 8
5 9
7 10
9 1
10 5
9
2 7
4 5
5 9
6 10
7 4
9 4
9 9
10 3
10 7
1
3 1...

output:

0
3
0
3
1
3
6
0
3
2
2
0
2
5
0
1
6
1
2
0
0
0
1
4
4
0
2
1
3
0
3
2
3
2
5
4
1
1
0
1
1
1
0
3
0
1
0
1
0
2
1
0
2
3
4
7
1
1
1
0
1
3
0
1
4
4
4
0
0
2
2
6
4
3
1
0
0
1
0
2
1
2
0
1
1
3
0
0
1
2
0
3
0
2
2
2
1
0
0
0
5
1
2
0
6
1
1
1
2
2
2
0
3
1
4
3
6
0
8
1
1
3
0
2
2
4
1
1
0
0
0
7
2
2
1
0
0
3
1
2
1
1
2
8
3
0
3
3
3
5
...

result:

wrong answer 17th lines differ - expected: '5', found: '6'