QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#87825#5369. 时间旅行Scintilla8 6ms3656kbC++143.6kb2023-03-14 14:34:192023-03-14 14:34:22

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-14 14:34:22]
  • 评测
  • 测评结果:8
  • 用时:6ms
  • 内存:3656kb
  • [2023-03-14 14:34:19]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define drep(i, s, e) for (int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)
#define pv(a) cout << #a << " = " << a << endl
#define pa(a, l, r) cout << #a " : "; rep(_, l, r) cout << a[_] << ' '; cout << endl

const int N = 6e2 + 10;

int read() {
  int x = 0, f = 1; char c = getchar();
  for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48;
  return x * f;
}

int n, k;
vector <int> a[N];

int pre[N], tag[N], p[N], dfn[N], dn, ans, p0[N], ans0;
bool e[N][N], e0[N][N];
queue <int> q;

int fa[N];
int get(int u) { return u == fa[u] ? u : fa[u] = get(fa[u]); }

int LCA(int u, int v) {
  for (++ dn; ; u = pre[p[u]], swap(u, v)) {
    if (dfn[u = get(u)] == dn) return u;
    else if (u) dfn[u] = dn;
  }
}

void shrink(int u, int v, int w) {
  for (; get(u) != w; u = pre[v]) {
    pre[u] = v, v = p[u], fa[u] = fa[v] = w;
    if (tag[v] == 2) q.push(v), tag[v] = 1;
  }
}

void rev(int u) {
  if (p[pre[u]]) rev(p[pre[u]]);
  p[pre[u]] = u, p[u] = pre[u];
}

bool blossom(int s) {
  // cout << "----- blossom s = " << s << endl;
  rep(i, 1, n + 1) pre[i] = tag[i] = 0, fa[i] = i;
  q = queue <int> (), tag[s] = 1, q.push(s);
  while (q.size()) {
    int u = q.front(); q.pop();
    rep(v, 1, n) if (e[u][v]) {
      if (tag[v] == 1) {
        int w = LCA(u, v);
        shrink(u, v, w), shrink(v, u, w);
      }
      else if (!tag[v]) {
        pre[v] = u, tag[v] = 2;
        if (!p[v]) {
          rev(v), ++ ans;
          return true;
        }
        tag[p[v]] = 1, q.push(p[v]);
      }
    }
  }
  return false;
}

bool check(int d) {
  // cout << "----- check d = " << d << endl;
  ans = dn = 0;
  rep(i, 1, n) {
    p[i] = dfn[i] = 0;
    rep(j, 1, n) e[i][j] = false;
  }
  auto adde = [&](int u, int v) {
    e[u][v] = e[v][u] = true;
  } ;
  rep(i, 1, n) rep(j, i + 1, n) {
    if (a[i][0] + d <= a[j].back()) adde(i, j);
    else if (a[j][0] + d <= a[i].back()) adde(i, j);
  }
  rep(i, 1, n) rep(j, 1, n) e0[i][j] = e[i][j];
  rep(i, 1, n) if (!p[i]) blossom(i);
  ans0 = ans;
  rep(i, 1, n) p0[i] = p[i];
  // pv(ans);
  rep(i, 1, n) {
    int x = i, y = n + 1;
    for (auto v : a[i]) {
      int cx = 0, cy = 0, px = -1, py = -1;
      rep(j, 1, n) if (j != i) {
        e[j][x] = e[x][j] = a[j][0] + d <= v;
        if (e[j][x]) ++ cx, px = j;
        e[j][y] = e[y][j] = v + d <= a[j].back();
        if (e[j][y]) ++ cy, py = j;
      }
      if (!cx || !cy || (cx == 1 && cy == 1 && px == py)) continue;
      auto work = [&](int u) {
        if (!p[u]) ans += blossom(u);
        else if (!e[u][p[u]]) {
          int z = p[u];
          p[u] = p[z] = 0, -- ans;
          ans += blossom(u);
          ans += !p[z] && blossom(z);
        }
      } ;
      work(x), work(y);
      if (ans > (n - k) / 2) return true;
    }
    ans = ans0;
    rep(j, 1, n) p[i] = p0[i], e[i][j] = e[j][i] = e0[i][j];
  }
  return false;
}

signed main() {
  n = read(), k = read();
  if (n - k & 1) return printf("Impossible\n"), 0;
  for (int i = 1, t; i <= n; ++ i) {
    a[i].resize(t = read());
    rep(j, 0, t - 1) a[i][j] = read();
    sort(a[i].begin(), a[i].end());
  }
  int l = 0, r = 1e18;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid + 1)) l = mid + 1;
    else r = mid;
  }
  printf("%lld\n", l);
  return 0;
}

详细

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 3
Accepted
time: 2ms
memory: 3548kb

input:

13 1
1 13
1 2
1 9
1 11
1 8
1 5
1 6
1 4
1 10
1 7
1 12
1 1
1 3

output:

6

result:

ok single line: '6'

Test #2:

score: 0
Accepted
time: 6ms
memory: 3656kb

input:

101 1
1 71
1 95
1 1
1 4
1 85
1 11
1 94
1 29
1 99
1 41
1 59
1 51
1 79
1 67
1 13
1 84
1 16
1 43
1 55
1 18
1 92
1 10
1 77
1 86
1 49
1 20
1 8
1 32
1 72
1 40
1 52
1 76
1 39
1 61
1 82
1 66
1 44
1 3
1 35
1 37
1 48
1 15
1 96
1 33
1 83
1 2
1 30
1 75
1 54
1 70
1 22
1 63
1 60
1 88
1 97
1 34
1 9
1 17
1 57
1 80
...

output:

50

result:

ok single line: '50'

Test #3:

score: -3
Time Limit Exceeded

input:

291 1
1 1
1 243
1 31
1 188
1 77
1 101
1 20
1 177
1 58
1 12
1 201
1 152
1 89
1 205
1 203
1 214
1 225
1 94
1 147
1 100
1 235
1 103
1 196
1 216
1 192
1 143
1 6
1 259
1 215
1 51
1 234
1 2
1 102
1 17
1 157
1 82
1 52
1 211
1 176
1 264
1 149
1 74
1 105
1 202
1 172
1 226
1 165
1 271
1 78
1 285
1 262
1 88
1 ...

output:


result:


Subtask #2:

score: 8
Accepted

Test #4:

score: 8
Accepted
time: 2ms
memory: 3580kb

input:

14 2
2 844974872 196961856
2 282529753 793092789
1 450615292
2 894675938 183278191
2 134804124 988858141
1 440476238
2 892091463 453193625
2 918614039 267044448
1 91126449
2 699070127 177282394
2 365458732 596469725
2 789994620 379428523
2 758349986 369167103
2 227448762 297426831

output:

392388416

result:

ok single line: '392388416'

Test #5:

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

input:

15 3
2 638683108 412097665
2 83585363 50407490
2 843046135 358173578
1 663325200
2 608604244 118346780
2 802365081 329993762
2 507345539 849824533
2 130234046 104894823
2 203433503 491790497
2 257479357 356611715
2 393337689 968844221
2 637493087 938737497
2 165665517 338554501
2 32482910 142430578
...

output:

461498682

result:

ok single line: '461498682'

Test #6:

score: 0
Accepted
time: 2ms
memory: 3620kb

input:

15 7
2 4067 4163
2 3780 4073
2 4060 4132
2 4115 4095
2 3801 4137
2 3767 4097
1 3976
1 4074
2 4141 4153
2 3965 4092
2 4080 3902
2 3863 4136
2 4153 4057
2 4045 3789
2 4117 4093

output:

198

result:

ok single line: '198'

Test #7:

score: 0
Accepted
time: 2ms
memory: 3556kb

input:

15 1
1 873331282220671423
2 735219904810912770 161751845932907141
2 25004270082210777 318839217154000771
2 674996277812508140 449008857311902192
2 472769470430097478 397080345283004274
2 47924412360460752 498222902664554012
2 564253525446680521 853694259885512872
2 656010667051096953 815344423905298...

output:

458440019518723706

result:

ok single line: '458440019518723706'

Test #8:

score: 0
Accepted
time: 2ms
memory: 3616kb

input:

15 13
2 896348312198404671 869762298
2 131322200859472553 156263978028639571
2 519956577 38
1 160595875
2 945987587 50986789140245249
2 41 241229344708873674
2 608655655392127091 41
1 40
2 806584170 50835315064131334
2 3623574246181054 976074155891825784
2 58183525 937860538
2 998266378 826367056
2 ...

output:

430005287589733910

result:

ok single line: '430005287589733910'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Dependency #2:

100%
Accepted

Test #22:

score: 0
Wrong Answer
time: 5ms
memory: 3592kb

input:

97 3
2 355271459380040532 547563913925852132
2 501938321780836726 747940481178452472
2 397422061492707294 74967044201975790
2 377923940791121468 378164526846394284
2 264704309452054653 529171612856996754
2 316250711337645385 284323194941392101
2 358629778571158126 368864454575116270
2 38360271038026...

output:

372997432997019311

result:

wrong answer 1st lines differ - expected: '372997432997019308', found: '372997432997019311'

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%