QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#396595#5109. Spider WalknguyentunglamRE 0ms0kbC++171.3kb2024-04-22 21:53:302024-04-22 21:53:31

Judging History

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

  • [2024-04-22 21:53:31]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-04-22 21:53:30]
  • 提交

answer

#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;

const int N = 1e5 + 10;

int f[N];

int n, m, s;

int32_t main() {
  #define task ""

  cin.tie(0) -> sync_with_stdio(0);

  if (fopen("task.inp", "r")) {
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
  }

  if (fopen(task".inp", "r")) {
    freopen (task".inp", "r", stdin);
    freopen (task".out", "w", stdout);
  }

  cin >> n >> m >> s;

  vector<pair<int, int> > e;

  while (m--) {
    int d, i; cin >> d >> i;
    d = -d;
    e.emplace_back(d, i);
  }

  sort(e.begin(), e.end());

  for(int i = 1; i <= n; i++) f[i] = 1e9;

  f[s] = 0;

  auto calc = [&] (int pos) {
    int ret = 1e9;
    for(int i = 1; i <= n; i++) {
      ret = min(ret, f[i] + min(n - abs(i - pos), abs(i - pos)));
    }
    return ret;
  };

  for(auto &[useless, i] : e) {
    int left = i > 1 ? i - 1 : n;
    int right = i + 2;
    if (right > n) right -= n;
    int x = i;
    int y = i + 1;
    if (y > n) y -= n;
    int tmpx = calc(x);
    int tmpy = calc(y);
    f[left] = min(f[left], f[x] + 1);
    f[right] = min(f[right], f[y] + 1);
    f[x] = tmpy;
    f[y] = tmpx;
  }
  for(int i = 1; i <= n; i++) cout << calc(i) << endl;
}




详细

Test #1:

score: 0
Runtime Error

input:

200000 500000 116205
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50...

output:


result: