QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#133951#4938. Writing TasksRd_rainydaysWA 107ms76536kbC++203.4kb2023-08-02 18:04:302023-08-02 18:04:33

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 18:04:33]
  • Judged
  • Verdict: WA
  • Time: 107ms
  • Memory: 76536kb
  • [2023-08-02 18:04:30]
  • Submitted

answer

#include <bits/stdc++.h>
using std::vector;
using std::tuple;
#define all(x) (x).begin(), (x).end()

const int N = 400005;
int A, C, T;
vector<int> L[N], F[N], S[N], ps[N];

int tot;
vector<int> adj[N];

std::map<tuple<int, int>, int> id;
vector<int> vs[N];

bool vis[N];
void solve() {
  for (int i = 1; i <= tot; i++)
    assert(adj[i].size() <= 2u);

  vector<int> ids;
  bool isRing = 0;
  int head = -1;
  auto dfs = [&](int x, int f, auto& dfs) -> void {
    ids.push_back(x);
    // printf("  dfs log : %d\n", x);
    vis[x] = 1;
    if (adj[x].size() == 1u) head = x;
    for (auto y : adj[x]) if (y != f) {
      if (vis[y] == 1) { isRing = 1; break; }
      dfs(y, x, dfs);
    }
  };

  int ans = 0;
  for (int i = 1; i <= tot; i++) {
    if (vis[i]) continue;

    isRing = 0, head = -1;
    ids.clear();
    dfs(i, 0, dfs);
    if (head != -1) std::reverse(ids.begin(), std::find(all(ids), head) + 1);

    // for (int id : ids)  
    //   printf(" %d ", id);
    // puts("");

    vector<std::array<int, 3>> dp(ids.size());    
    auto do_trans = [&](int exclude) -> int {
      for (int j = 1; j < (int)ids.size(); j++) {
        int cur = ids[j], pre = ids[j - 1];
        for (int t = 0; t < (int)vs[cur].size(); t++)
          dp[j][t + 1] = dp[j - 1][0] + 1;
        dp[j][0] = *std::max_element(all(dp[j - 1]));
        // trivial

        for (int t = 0; t < (int)vs[cur].size(); t++)
          for (int s = 0; s < (int)vs[pre].size(); s++) {
            if (vs[cur][t] == vs[pre][s]) continue;
            dp[j][t] = std::max(dp[j][t], dp[j - 1][s] + 1);
          }
      }
      
      int cur_ans = 0;
      for (int i = 0; i < 3; i++) {
        if (i == exclude && exclude > 0) continue;
        cur_ans = std::max(cur_ans, dp.back()[i]);
      }
      return cur_ans;
    };

    if (!isRing) {
      dp.assign(ids.size(), {0, 0, 0});
      dp[0][0] = 0;
      for (int t = 0; t < (int)vs[ids[0]].size(); t++)
        dp[0][t + 1] = 1;
      ans += do_trans(0);
    } else {
      vector<int> cadi;
      for (int ex = 0; ex <= (int)vs[ids[0]].size(); ex++) {
        dp.assign(ids.size(), {0, 0, 0});
        dp[0][ex] = (ex > 0);
        cadi.push_back(do_trans(ex));
      }
      ans += *std::max_element(all(cadi));
    }

    // printf(" >> %d\n", ans);
  }

  printf("%d\n", ans);
  return;
}

int main() {
  scanf("%d%d%d", &A, &C, &T);

  for (int i = 1; i <= A; i++) {
    int sz;
    scanf("%d", &sz);
    L[i].resize(sz);
    for (auto &x : L[i]) scanf("%d", &x);
  }

  for (int i = 1; i <= A; i++) {
    int sz;
    scanf("%d", &sz);
    F[i].resize(sz);
    for (auto &x : F[i]) scanf("%d", &x);
  }

  for (int i = 1; i <= C; i++) {
    int sz;
    scanf("%d", &sz);
    S[i].resize(sz);
    for (auto &x : S[i]) {
      scanf("%d", &x);
      ++tot;
      ps[x].push_back(tot);
      id[{i, x}] = tot;
    }

    if (sz == 2) {
      adj[tot].push_back(tot - 1);
      adj[tot - 1].push_back(tot);
    }
  }

  for (int i = 1; i <= T; i++)
    if ((int)ps[i].size() == 2) {
      adj[ps[i][0]].push_back(ps[i][1]);
      adj[ps[i][1]].push_back(ps[i][0]);
    }

  for (int i = 1; i <= A; i++)
    for (auto l : L[i]) for (auto f : F[i])
      vs[id[{l, f}]].push_back(i);

  solve();
  return 0;
}
/*
2 3 2
2 1 2
2 2 3
1 1
1 1
1 1
1 1
1 2

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 3ms
memory: 60028kb

input:

2 2 2
0
1 2
0
2 1 2
2 1 2
0

output:

0

result:

ok single line: '0'

Test #3:

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

input:

40623 39265 42226
2 14643 37432
2 29610 20181
2 6441 7614
2 17559 3238
2 39001 17644
2 6431 37097
2 6347 12246
2 1130 1688
2 38583 9078
2 8746 27832
2 13090 39048
2 32647 18777
2 27505 19277
2 31201 25824
2 6133 20344
2 11625 20997
2 18528 35730
0
2 22986 5273
2 10942 38791
2 19025 35679
2 32321 124...

output:

78528

result:

ok single line: '78528'

Test #4:

score: 0
Accepted
time: 90ms
memory: 74936kb

input:

41022 39421 42288
2 26413 2168
2 24182 14199
2 18798 17846
2 3398 19624
2 16796 33998
2 7209 25883
2 26356 13537
2 56 30294
2 34909 20218
2 29727 22116
2 16349 1704
2 9254 18036
2 16197 16096
2 21562 31470
2 14773 10518
2 38025 12573
2 15509 32276
2 9613 12321
2 19146 11395
2 7186 36431
0
2 10098 22...

output:

78840

result:

ok single line: '78840'

Test #5:

score: 0
Accepted
time: 107ms
memory: 76536kb

input:

49395 43808 45888
2 13031 11323
2 41375 4393
2 32137 17908
2 29053 42691
0
2 38335 30970
2 38318 43773
2 22999 22444
0
2 39248 30837
0
2 29807 2360
2 29363 3536
2 8515 41137
2 7890 31441
0
2 31070 6987
2 24295 15517
2 14204 13069
2 32996 40146
2 38164 1478
2 40032 19143
0
2 18430 24119
2 37845 33290...

output:

87616

result:

ok single line: '87616'

Test #6:

score: -100
Wrong Answer
time: 17ms
memory: 60216kb

input:

3 4 3
1 2
2 4 2
2 1 3
1 1
2 2 3
2 3 2
1 3
2 1 3
1 2
1 2

output:

3

result:

wrong answer 1st lines differ - expected: '5', found: '3'