Submission #95445

# Submission time Handle Problem Language Result Execution time Memory
95445 2019-02-01T08:39:35 Z forestryks Sailing Race (CEOI12_race) C++14
Compilation error
0 ms 0 KB
///////////////////////////////////////////////////////////////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout)
#define f first
#define s second///////////////////////////////////////////////////////////////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define FILE_IO(x) freopen((string(x) + ".in").c_str(), "r", stdin); freopen((string(x) + ".out").c_str(), "w", stdout)
#define f first
#define s second
#define x1 x1qwer
#define y1 y1qwer
#define right right123
#define left left123
#define foreach(it, v) for (auto it : v)
#define rep(it, n) for (int it = 0; it < n; ++it)
#define forin(it, l, r) for (int it = l; it < r; ++it)
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double DINF = numeric_limits<double>::infinity();
const ll MOD = 1e9 + 7;
const double EPS = 1e-7;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
mt19937 mmtw_(MOD);
uniform_int_distribution<ll> rd_;
ll randomll() { return rd_(mmtw_);}
ll rnd(ll x, ll y) { return rd_(mmtw_) % (y - x + 1) + x; }
////////////////////////////////////////////////////////////////////////////////////////////////

const int MAXN = 505;
int n, k;
bool g[MAXN][MAXN];
int dp[MAXN][MAXN];
int dpc[MAXN][MAXN];
int ds[MAXN][MAXN];
int dsc[MAXN][MAXN];

inline int md(int x) {
    if (x >= n) return x - n;
    if (x < 0) return x + n;
    return x;
}

int f(int, int);
int fc(int, int);

int f(int a, int b) {
    if (dp[a][b] != -1) return dp[a][b];

    dp[a][b] = 0;
    for (int i = md(b + 1); i != a; i = md(i + 1)) {
        if (g[b][i]) dp[a][b] = max(dp[a][b], max(fc(b, i), f(a, i)) + 1);
    }

    return dp[a][b];
}

int fc(int a, int b) {
    if (dpc[a][b] != -1) return dpc[a][b];

    dpc[a][b] = 0;
    for (int i = md(b - 1); i != a; i = md(i - 1)) {
        if (g[b][i]) dpc[a][b] = max(dpc[a][b], max(f(b, i), fc(a, i)) + 1);
    }

    return dpc[a][b];
}

int s(int a, int b) {
    if (ds[a][b] != -2) return ds[a][b];

    ds[a][b] = -1;
    if (a == b) ds[a][b] = 0;
    if (g[a][b]) ds[a][b] = 1;
    for (int i = md(a + 1); i != b; i = md(i + 1)) {
        int ai = s(a, i);
        int ib = s(i, b);
        if (ai == -1 || ib == -1) continue;
        ds[a][b] = max(ds[a][b], ai + ib);
    }

    return ds[a][b];
}

int sc(int a, int b) {
    if (dsc[a][b] != -2) return dsc[a][b];

    dsc[a][b] = -1;
    if (a == b) dsc[a][b] = 0;
    if (g[a][b]) dsc[a][b] = 1;
    for (int i = md(a - 1); i != b; i = md(i - 1)) {
        int ai = sc(a, i);
        int ib = sc(i, b);
        if (ai == -1 || ib == -1) continue;
        dsc[a][b] = max(dsc[a][b], ai + ib);
    }

    return dsc[a][b];
}

int main() {
    FAST_IO;
    cin >> n >> k;
    rep(i, n) {
        while (true) {
            int x;
            cin >> x;
            x--;
            if (x == -1) break;
            g[i][x] = true;
        }
    }

    rep(i, n) {
        rep(j, n) {
            dp[i][j] = dpc[i][j] = -1;
            ds[i][j] = dsc[i][j] = -2;
        }
    }

    int res = 0;
    int st = 0;
    rep(i, n) {
        rep(j, n) {
            if (i == j) continue;
            if (g[i][j]) {
                int nw = max(f(i, j), fc(i, j)) + 1;
                if (nw > res) {
                    res = nw;
                    st = i;
                }
            }
        }
    }

    if (k == 1) {
        rep(b, n) {
            rep(c, n) {
                if (b == c) continue;
                if (s(b, c) == -1) continue;

                int a;
                for (a = md(c + 1); a != b; a = md(a + 1)) {
                    if (g[a][b]) break;
                }

                if (a == b) continue;

                for (int d = md(a + 1); d != b; d = md(d + 1)) {
                    if (!g[c][d]) continue;
                    int nw = 2 + s(b, c) + max(f(b, d), fc(a, d));
                    if (nw > res) {
                        res = nw;
                        st = a;
                    }
                }
            }
        }

        rep(b, n) {
            rep(c, n) {
                if (b == c) continue;
                if (sc(b, c) == -1) continue;

                int a;
                for (a = md(c - 1); a != b; a = md(a - 1)) {
                    if (g[a][b]) break;
                }

                if (a == b) continue;

                for (int d = md(a - 1); d != b; d = md(d - 1)) {
                    if (!g[c][d]) continue;
                    int nw = 2 + sc(b, c) + max(fc(b, d), f(a, d));
                    if (nw > res) {
                        res = nw;
                        st = a;
                    }
                }
            }
        }
    }

    cout << res << endl;
    cout << st + 1 << endl;
}

#define x1 x1qwer
#define y1 y1qwer
#define right right123
#define left left123
#define foreach(it, v) for (auto it : v)
#define rep(it, n) for (int it = 0; it < n; ++it)
#define forin(it, l, r) for (int it = l; it < r; ++it)
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double DINF = numeric_limits<double>::infinity();
const ll MOD = 1e9 + 7;
const double EPS = 1e-7;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
mt19937 mmtw_(MOD);
uniform_int_distribution<ll> rd_;
ll randomll() { return rd_(mmtw_);}
ll rnd(ll x, ll y) { return rd_(mmtw_) % (y - x + 1) + x; }
////////////////////////////////////////////////////////////////////////////////////////////////

const int MAXN = 505;
int n, k;
bool g[MAXN][MAXN];
int dp[MAXN][MAXN];
int dpc[MAXN][MAXN];
int ds[MAXN][MAXN];
int dsc[MAXN][MAXN];

inline int md(int x) {
    if (x >= n) return x - n;
    if (x < 0) return x + n;
    return x;
}

int f(int, int);
int fc(int, int);

int f(int a, int b) {
    if (dp[a][b] != -1) return dp[a][b];

    dp[a][b] = 0;
    for (int i = md(b + 1); i != a; i = md(i + 1)) {
        if (g[b][i]) dp[a][b] = max(dp[a][b], max(fc(b, i), f(a, i)) + 1);
    }

    return dp[a][b];
}

int fc(int a, int b) {
    if (dpc[a][b] != -1) return dpc[a][b];

    dpc[a][b] = 0;
    for (int i = md(b - 1); i != a; i = md(i - 1)) {
        if (g[b][i]) dpc[a][b] = max(dpc[a][b], max(f(b, i), fc(a, i)) + 1);
    }

    return dpc[a][b];
}

int s(int a, int b) {
    if (ds[a][b] != -2) return ds[a][b];

    ds[a][b] = -1;
    if (a == b) ds[a][b] = 0;
    if (g[a][b]) ds[a][b] = 1;
    for (int i = md(a + 1); i != b; i = md(i + 1)) {
        int ai = s(a, i);
        int ib = s(i, b);
        if (ai == -1 || ib == -1) continue;
        ds[a][b] = max(ds[a][b], ai + ib);
    }

    return ds[a][b];
}

int sc(int a, int b) {
    if (dsc[a][b] != -2) return dsc[a][b];

    dsc[a][b] = -1;
    if (a == b) dsc[a][b] = 0;
    if (g[a][b]) dsc[a][b] = 1;
    for (int i = md(a - 1); i != b; i = md(i - 1)) {
        int ai = sc(a, i);
        int ib = sc(i, b);
        if (ai == -1 || ib == -1) continue;
        dsc[a][b] = max(dsc[a][b], ai + ib);
    }

    return dsc[a][b];
}

int main() {
    FAST_IO;
    cin >> n >> k;
    rep(i, n) {
        while (true) {
            int x;
            cin >> x;
            x--;
            if (x == -1) break;
            g[i][x] = true;
        }
    }

    rep(i, n) {
        rep(j, n) {
            dp[i][j] = dpc[i][j] = -1;
            ds[i][j] = dsc[i][j] = -2;
        }
    }

    int res = 0;
    int st = 0;
    rep(i, n) {
        rep(j, n) {
            if (i == j) continue;
            if (g[i][j]) {
                int nw = max(f(i, j), fc(i, j)) + 1;
                if (nw > res) {
                    res = nw;
                    st = i;
                }
            }
        }
    }

    rep(b, n) {
        rep(c, n) {
            if (b == c) continue;
            if (s(b, c) == -1) continue;

            int a;
            for (a = md(c + 1); a != b; a = md(a + 1)) {
                if (g[a][b]) break;
            }

            if (a == b) continue;

            for (int d = md(a + 1); d != b; d = md(d + 1)) {
                if (!g[c][d]) continue;
                int nw = 2 + s(b, c) + max(f(b, d), fc(a, d));
                if (nw > res) {
                    res = nw;
                    st = a;
                }
            }
        }
    }

    rep(b, n) {
        rep(c, n) {
            if (b == c) continue;
            if (sc(b, c) == -1) continue;

            int a;
            for (a = md(c - 1); a != b; a = md(a - 1)) {
                if (g[a][b]) break;
            }

            if (a == b) continue;

            for (int d = md(a - 1); d != b; d = md(d - 1)) {
                if (!g[c][d]) continue;
                int nw = 2 + sc(b, c) + max(fc(b, d), f(a, d));
                if (nw > res) {
                    res = nw;
                    st = a;
                }
            }
        }
    }


    cout << res << endl;
    cout << st + 1 << endl;
}

Compilation message

race.cpp:216:14: error: redefinition of 'const double DINF'
 const double DINF = numeric_limits<double>::infinity();
              ^~~~
race.cpp:34:14: note: 'const double DINF' previously defined here
 const double DINF = numeric_limits<double>::infinity();
              ^~~~
race.cpp:217:10: error: redefinition of 'const ll MOD'
 const ll MOD = 1e9 + 7;
          ^~~
race.cpp:35:10: note: 'const ll MOD' previously defined here
 const ll MOD = 1e9 + 7;
          ^~~
race.cpp:218:14: error: redefinition of 'const double EPS'
 const double EPS = 1e-7;
              ^~~
race.cpp:36:14: note: 'const double EPS' previously defined here
 const double EPS = 1e-7;
              ^~~
race.cpp: In function 'll gcd(ll, ll)':
race.cpp:219:4: error: redefinition of 'll gcd(ll, ll)'
 ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
    ^~~
race.cpp:37:4: note: 'll gcd(ll, ll)' previously defined here
 ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
    ^~~
race.cpp: At global scope:
race.cpp:220:18: error: redefinition of 'std::mt19937 mmtw_'
 mt19937 mmtw_(MOD);
                  ^
race.cpp:38:9: note: 'std::mt19937 mmtw_' previously declared here
 mt19937 mmtw_(MOD);
         ^~~~~
race.cpp:221:30: error: redefinition of 'std::uniform_int_distribution<long long int> rd_'
 uniform_int_distribution<ll> rd_;
                              ^~~
race.cpp:39:30: note: 'std::uniform_int_distribution<long long int> rd_' previously declared here
 uniform_int_distribution<ll> rd_;
                              ^~~
race.cpp: In function 'll randomll()':
race.cpp:222:4: error: redefinition of 'll randomll()'
 ll randomll() { return rd_(mmtw_);}
    ^~~~~~~~
race.cpp:40:4: note: 'll randomll()' previously defined here
 ll randomll() { return rd_(mmtw_);}
    ^~~~~~~~
race.cpp: In function 'll rnd(ll, ll)':
race.cpp:223:4: error: redefinition of 'll rnd(ll, ll)'
 ll rnd(ll x, ll y) { return rd_(mmtw_) % (y - x + 1) + x; }
    ^~~
race.cpp:41:4: note: 'll rnd(ll, ll)' previously defined here
 ll rnd(ll x, ll y) { return rd_(mmtw_) % (y - x + 1) + x; }
    ^~~
race.cpp: At global scope:
race.cpp:226:11: error: redefinition of 'const int MAXN'
 const int MAXN = 505;
           ^~~~
race.cpp:44:11: note: 'const int MAXN' previously defined here
 const int MAXN = 505;
           ^~~~
race.cpp:227:5: error: redefinition of 'int n'
 int n, k;
     ^
race.cpp:45:5: note: 'int n' previously declared here
 int n, k;
     ^
race.cpp:227:8: error: redefinition of 'int k'
 int n, k;
        ^
race.cpp:45:8: note: 'int k' previously declared here
 int n, k;
        ^
race.cpp:228:18: error: redefinition of 'bool g [505][505]'
 bool g[MAXN][MAXN];
                  ^
race.cpp:46:6: note: 'bool g [505][505]' previously declared here
 bool g[MAXN][MAXN];
      ^
race.cpp:229:18: error: redefinition of 'int dp [505][505]'
 int dp[MAXN][MAXN];
                  ^
race.cpp:47:5: note: 'int dp [505][505]' previously declared here
 int dp[MAXN][MAXN];
     ^~
race.cpp:230:19: error: redefinition of 'int dpc [505][505]'
 int dpc[MAXN][MAXN];
                   ^
race.cpp:48:5: note: 'int dpc [505][505]' previously declared here
 int dpc[MAXN][MAXN];
     ^~~
race.cpp:231:18: error: redefinition of 'int ds [505][505]'
 int ds[MAXN][MAXN];
                  ^
race.cpp:49:5: note: 'int ds [505][505]' previously declared here
 int ds[MAXN][MAXN];
     ^~
race.cpp:232:19: error: redefinition of 'int dsc [505][505]'
 int dsc[MAXN][MAXN];
                   ^
race.cpp:50:5: note: 'int dsc [505][505]' previously declared here
 int dsc[MAXN][MAXN];
     ^~~
race.cpp: In function 'int md(int)':
race.cpp:234:12: error: redefinition of 'int md(int)'
 inline int md(int x) {
            ^~
race.cpp:52:12: note: 'int md(int)' previously defined here
 inline int md(int x) {
            ^~
race.cpp: In function 'int first(int, int)':
race.cpp:18:11: error: redefinition of 'int first(int, int)'
 #define f first
           ^
race.cpp:243:5: note: in expansion of macro 'f'
 int f(int a, int b) {
     ^
race.cpp:18:11: note: 'int first(int, int)' previously defined here
 #define f first
           ^
race.cpp:61:5: note: in expansion of macro 'f'
 int f(int a, int b) {
     ^
race.cpp: In function 'int fc(int, int)':
race.cpp:254:5: error: redefinition of 'int fc(int, int)'
 int fc(int a, int b) {
     ^~
race.cpp:72:5: note: 'int fc(int, int)' previously defined here
 int fc(int a, int b) {
     ^~
race.cpp: In function 'int second(int, int)':
race.cpp:19:11: error: redefinition of 'int second(int, int)'
 #define s second
           ^
race.cpp:265:5: note: in expansion of macro 's'
 int s(int a, int b) {
     ^
race.cpp:19:11: note: 'int second(int, int)' previously defined here
 #define s second
           ^
race.cpp:83:5: note: in expansion of macro 's'
 int s(int a, int b) {
     ^
race.cpp: In function 'int sc(int, int)':
race.cpp:281:5: error: redefinition of 'int sc(int, int)'
 int sc(int a, int b) {
     ^~
race.cpp:99:5: note: 'int sc(int, int)' previously defined here
 int sc(int a, int b) {
     ^~
race.cpp: In function 'int main()':
race.cpp:297:5: error: redefinition of 'int main()'
 int main() {
     ^~~~
race.cpp:115:5: note: 'int main()' previously defined here
 int main() {
     ^~~~