Submission #224595

# Submission time Handle Problem Language Result Execution time Memory
224595 2020-04-18T13:27:31 Z farmerboy OBELISK (NOI14_obelisk) C++14
5 / 25
52 ms 1608 KB
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 510;
const int MAXM = 110;
const int MAXK = 16;
const int MAXQ = 200010;

int N, M;
vector<II> a[MAXN];
ll d[MAXN][MAXM];

ll sameLine(int x) {
    return 2 + x;
}

ll check(int x, int y) {
    if (x == 0) return sameLine(y);
    if (y == 0) return sameLine(x);
    return x + y + 4;
}

ll dist(int x, int y, int u, int v, int m) {
    x -= u;
    y -= v;
    x = abs(x); y = abs(y);
    if (m == 1) return x + y;
    ll res = 2 * (x / (m+1) + y / (m+1));
    x %= m+1; y %= m+1;
    if (x == 0 && y == 0) return res;
    return res + min(min(check(x, y), check(m+1-x, y)), min(check(x, m+1-y), check(m+1-x, m+1-y)));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int x, y;
    cin >> N >> M;
    cin >> x >> y;
    a[0].push_back(II(x, y));
    cin >> x >> y;
    a[N].push_back(II(x, y));

    FOR(i,1,N-1) {
        int k;
        cin >> k;
        while (k--) {
            cin >> x >> y;
            a[i].push_back(II(x, y));
        }
    }

    FOR(i,0,505) FOR(j,0,100) d[i][j] = 1e18;
    d[0][0] = 0;

    FOR(i,1,N)
        FOR(j,0,SZ(a[i-1])-1)
            FOR(k,0,SZ(a[i])-1) d[i][k] = min(d[i][k], d[i-1][j] + dist(a[i-1][j].FI, a[i-1][j].SE, a[i][k].FI, a[i][k].SE, M));
    
    cout << d[N][0];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 768 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Correct 5 ms 768 KB Output is correct
4 Correct 5 ms 768 KB Output is correct
5 Correct 5 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 1280 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 1608 KB Output isn't correct
2 Halted 0 ms 0 KB -