Submission #64522

#TimeUsernameProblemLanguageResultExecution timeMemory
64522dfistricSailing Race (CEOI12_race)C++14
40 / 100
1912 ms8128 KiB
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

using namespace std;

const int MAXN = 510;
vector <int> ve[MAXN];
int num_ways[MAXN][MAXN][2];
int max_ways[MAXN][MAXN][2];
int dp[MAXN][MAXN][2];

bool inside(int x, int y, int z, int t) {
  if (t == 0) swap(x, y);
  if (x < y) {
    return ((z > x) && (z < y));
  }
  return ((z > x) || (z < y));
}

int rek(int x, int y, int t) {
  int& out = num_ways[x][y][t];
  if (out != -1) return out;

  out = 0;
  for (int z : ve[y]) {
    if (inside(x, y, z, t)) {
      out = max(out, 1 + max(rek(y, z, 1 - t), rek(x, z, t)));
    }
  }

  return out;
}

int dfs(int x, int y, int t) {
  int& out = dp[x][y][t];
  if (out != -1) return out;

  out = 0;
  for (int z : ve[y]) {
    if (inside(x, y, z, t) || z == y) {
      out = max(out, 1 + dfs(z, y, t));
    }
  }

  return out;
}

int main() {
  ios_base::sync_with_stdio(false);
  memset(num_ways, -1, sizeof num_ways);
  memset(dp, -1, sizeof dp);

  int n, k;
  cin >> n >> k;
  REP(i, n) {
    int x;
    cin >> x;
    while (x) {
      ve[i].push_back(x - 1);
      cin >> x;
    }
  }

  int out = 0, st = 0;
  REP(i, n) {
    for (int j : ve[i]) {
      int tr = 1 + max(rek(i, j, 1), rek(i, j, 0));
      if (tr > out) {
        out = tr;
        st = i + 1;
      }
    }
  }

  if (!k) {
    cout << out << "\n" << st << "\n";
    return 0;
  }

  REP(a, n) {
    REP(b, n) {
      if (a == b) continue;
      int c = a + 1;
      while (c != b) {
        max_ways[a][b][0] = max(max_ways[a][b][0], rek(b, c, 0));
        max_ways[a][b][1] = max(max_ways[a][b][1], rek(a, c, 1));
        c = (c + 1) % n;
      }
    }
  }

  REP(i, n) dp[i][i][0] = dp[i][i][1] = 0;

  REP(a, n) {
    for (int b : ve[a]) {
      REP(c, n) {
        if (c == b || c == a) continue;
        int tr = 0;
      }
    }
  }
  


  return 0;
}

Compilation message (stderr)

race.cpp: In function 'int main()':
race.cpp:100:13: warning: unused variable 'tr' [-Wunused-variable]
         int tr = 0;
             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...