QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#87849#5369. 时间旅行Scintilla8 408ms3976kbC++143.6kb2023-03-14 15:17:322023-03-14 15:17:33

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 15:17:33]
  • 评测
  • 测评结果:8
  • 用时:408ms
  • 内存:3976kb
  • [2023-03-14 15:17:32]
  • 提交

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 + 1) 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 + 1) {
    p[i] = dfn[i] = 0;
    rep(j, 1, n + 1) 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];
  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]) blossom(u);
        else if (!e[u][p[u]]) {
          int z = p[u];
          p[u] = p[z] = 0, -- ans;
          blossom(u);
          if (!p[z]) blossom(z);
        }
      } ;
      work(x), work(y);
      if (ans > (n - k) / 2) return true;
    }
    ans = ans0, p[n + 1] = 0;
    rep(j, 1, n) {
      p[j] = p0[j];
      e[x][j] = e[j][x] = e0[x][j];
      e[y][j] = e[j][y] = false;
    }
  }
  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: 3
Accepted

Test #1:

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

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: 7ms
memory: 3748kb

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: 0
Accepted
time: 78ms
memory: 3876kb

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:

145

result:

ok single line: '145'

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 2ms
memory: 3632kb

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:

478137801

result:

wrong answer 1st lines differ - expected: '392388416', found: '478137801'

Subtask #3:

score: 5
Accepted

Dependency #1:

100%
Accepted

Test #9:

score: 5
Accepted
time: 374ms
memory: 3792kb

input:

287 1
1 173840701363378004
1 743361258032855446
1 746614854489854642
1 56541606566914354
1 420238720727662982
1 851742472173310082
1 663095483358412253
1 909940213272622771
1 793226013158281220
1 545752184531876147
1 428168322861170312
1 445062401949703086
1 781910693870313013
1 656624250154096657
1...

output:

449906768878285431

result:

ok single line: '449906768878285431'

Test #10:

score: 0
Accepted
time: 337ms
memory: 3976kb

input:

291 1
1 200467876183364735
1 226128802768594222
1 30992945592387546
1 131773707522781490
1 237517614711585543
1 767178437925265104
1 476367111669121061
1 569219147773036356
1 307153686500641679
1 256093763487190540
1 489553827811869668
1 665158752209826021
1 821778345278263808
1 591434397265270731
1...

output:

413750515661326196

result:

ok single line: '413750515661326196'

Test #11:

score: 0
Accepted
time: 89ms
memory: 3904kb

input:

299 1
1 196564096074155356
1 215761209458809063
1 229199188828066663
1 207442460325459123
1 147931408833032623
1 165208810879220961
1 156890061745871023
1 281031394966631680
1 190804962058759240
1 165848714658709418
1 274632357171747109
1 178006886468990102
1 183126116704897759
1 263753992920443339
...

output:

95345663143780088

result:

ok single line: '95345663143780088'

Test #12:

score: 0
Accepted
time: 181ms
memory: 3788kb

input:

291 1
1 33421439583378802
1 58525406002796904
1 59037731848091151
1 71845877980447328
1 54939125085737173
1 56305327339855169
1 59720832975150147
1 42814080080439994
1 38886248599850767
1 34446091273967295
1 80213866786920026
1 80384642068684774
1 58866956566326401
1 74919833052212806
1 674057206545...

output:

24762415855888600

result:

ok single line: '24762415855888600'

Test #13:

score: 0
Accepted
time: 108ms
memory: 3976kb

input:

299 1
1 65691845888395612
1 216175196973785149
1 60434785588469342
1 137319292474891070
1 61749050663450912
1 160976063824559296
1 86720087088100703
1 218803727123748287
1 169518786811939488
1 153747605912160670
1 165575991586994780
1 141919220237326556
1 35463749163819549
1 188575630399172220
1 145...

output:

97912748086126811

result:

ok single line: '97912748086126811'

Subtask #4:

score: 0
Wrong Answer

Dependency #3:

100%
Accepted

Test #14:

score: 12
Accepted
time: 298ms
memory: 3832kb

input:

298 12
1 645886088791049540
1 426745180837601651
1 979147412433797722
1 922061238106952073
1 274440630526214995
1 424124977235014990
1 204894438049963221
1 764943184717907334
1 779533900124364741
1 454823872376348471
1 487382439634807111
1 591648739045233572
1 53460960257864384
1 392937311085787220
...

output:

446040287477110394

result:

ok single line: '446040287477110394'

Test #15:

score: 0
Accepted
time: 408ms
memory: 3724kb

input:

285 3
1 915828826922386175
1 908205342117914832
1 873896977912303819
1 656558831677725931
1 576889220915038574
1 104013515132123991
1 706177613718527725
1 198684931909293626
1 494902099840825229
1 89161767331355640
1 178478456398904787
1 115932633756444471
1 138418817497444484
1 414147023206092509
1...

output:

402109191950085563

result:

ok single line: '402109191950085563'

Test #16:

score: 0
Accepted
time: 356ms
memory: 3876kb

input:

290 8
1 87958755742337433
1 257381168536262370
1 937989408112804408
1 194798272982765279
1 498991322819486370
1 977524249586089037
1 912136601439828528
1 500742285087273119
1 33135176968228980
1 940337323147451787
1 646963258773910853
1 826406775797523718
1 235531045573726392
1 952251530552011077
1 ...

output:

381364661745038978

result:

ok single line: '381364661745038978'

Test #17:

score: 0
Accepted
time: 61ms
memory: 3848kb

input:

286 2
1 275543708198154703
1 249566763748953083
1 144254826792730280
1 189187919894052009
1 270629151140197641
1 194102476952009076
1 246056365850412323
1 263608355343116123
1 262906275763407971
1 250268843328661233
1 160402657126017777
1 210250307285296570
1 225696058038875911
1 150573543010103650
...

output:

99695300318557576

result:

ok single line: '99695300318557576'

Test #18:

score: -12
Wrong Answer
time: 55ms
memory: 3868kb

input:

300 12
1 164380439043062353
1 124158335088338941
1 96965926780920306
1 64108433409456117
1 119626267037102508
1 57876839839006013
1 197804440920931095
1 166646473068680572
1 178543151703176224
1 100931486325752192
1 52211754774960459
1 177410134690367115
1 114527690479461513
1 204036034491381198
1 2...

output:

81577224922255915

result:

wrong answer 1st lines differ - expected: '81577224922255913', found: '81577224922255915'

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%