QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#368304#2832. Graph TheorykoalaRE 0ms3772kbC++201.6kb2024-03-26 23:21:562024-03-26 23:21:57

Judging History

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

  • [2024-03-26 23:21:57]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3772kb
  • [2024-03-26 23:21:56]
  • 提交

answer

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie(0);
  int n, m;
  while (cin >> n >> m) {
    vector<int> a(m), b(m);
    vector<pair<int, int>> v;
    priority_queue<int> que;
    map<int, int> cnt;

    for (int i = 0; i < m; ++i) {
      cin >> a[i] >> b[i];
      if (a[i] == b[i])
        continue;
      if (a[i] > b[i])
        swap(a[i], b[i]);

      v.push_back({a[i], i});
      if (b[i] != n)
        v.push_back({b[i], i});
      que.push(b[i] - a[i]);
    }
    if (v.size() == 0) {
      cout << 0 << '\n';
      continue;
    }
    sort(v.begin(), v.end());
    vector<int> used(n * 2 + 1);
    int ans = 1e9;
    int lst = n;
    auto get = [&]() {
      while (cnt[que.top()]) {
        cnt[que.top()]--;
        que.pop();
      }
      return que.top();
    };
    for (auto [_, y] : v) {
      int now;
      if (used[y]) {
        now = b[y];
        if (now != lst) {
          ans = min(ans, get());
          lst = now;
        }
        cnt[abs(a[y] - b[y])]++;
        b[y] += n;

      } else {
        now = a[y];
        if (now != lst) {
          ans = min(ans, get());
          lst = now;
        }
        cnt[abs(a[y] - b[y])]++;
        a[y] += n;
      }

      used[y]++;
      que.push(abs(a[y] - b[y]));
    }
    // cout << get() << '\n';
    ans = min(ans, get());
    cout << ans << '\n';
  }

  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3772kb

input:

3 2
1 2
2 3
3 2
1 1
2 2
3 3
1 2
2 3
3 1

output:

1
0
2

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3500kb

input:

2 1
1 2

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Runtime Error

input:

17 17
6 10
1 9
14 6
12 13
5 4
15 17
14 15
6 5
10 6
10 11
2 9
9 6
17 15
9 15
4 8
1 4
13 15
13 19
11 10
12 10
10 5
2 8
12 11
8 3
1 7
10 9
8 5
1 5
9 4
8 7
12 10
6 8
13 1
5 8
11 5
10 8
7 7
16 14
9 5
8 1
4 16
10 8
16 15
15 1
13 5
9 3
4 4
9 7
7 2
5 4
5 11
9 14
5 13
1 5
4 5
4 1
4 4
1 1
5 3
3 5
4 1
3 2
5 1
...

output:

8
6
8
2
1
3

result: