Submission #208100

# Submission time Handle Problem Language Result Execution time Memory
208100 2020-03-10T03:05:43 Z ToMmyDong Coin Collecting (JOI19_ho_t4) C++11
37 / 100
119 ms 40544 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define REP(i,n) for(int i=0;i<n;++i)
#define REP1(i,n) for(int i=1;i<=n;++i)
#define SZ(i) int(i.size())
#define eb emplace_back
#define ALL(i) i.begin(),i.end()
#define X first
#define Y second
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"#%d: %s = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
template<typename It> ostream& _printRng(ostream &os,It bg,It ed)
{
    os<<"{";
    for(It it=bg;it!=ed;it++) {
        os<<(it==bg?"":",")<<*it;
    }
    os<<"}";
    return os;
}
template<typename T> ostream &operator << (ostream &os,vector<T> &v){return _printRng(os,v.begin(), v.end());}
template<typename T> void pary(T bg, T ed){_printRng(cerr,bg,ed);cerr<<endl;}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#define pary(...)
#endif

const int MAXN = 1003;
const ll MOD = 1000000007;

int n;
vector<pll> pos;

void solve (vector<int> x, ll &res) {
    sort(ALL(x));

    for (int i=1; i<=n; i++) {
        res += abs(x[i-1] - i);
    }
}

ll dp[MAXN*2][MAXN];

void ckmin (ll &x, ll y) {
    x = x > y ? y : x;
}
/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> n;

    REP (i, n*2) {
        int x, y;
        cin >> x >> y;
        pos.eb(x, y);
    }

    sort(ALL(pos));

    memset(dp, 0x3f, sizeof(dp));
    dp[0][0] = 0;

    for (int i=1; i<=n*2; i++) {
        for (int u=0; u<=min(i,n); u++) {
            int d = i-u;
            if (d < 0 || d > n) {
                continue;
            }

            if (d > 0) {
                ckmin(dp[i][u],dp[i-1][u] + abs(pos[i-1].X - d) + abs(pos[i-1].Y - 1));
            }

            if (u > 0) {
                ckmin(dp[i][u],dp[i-1][u-1] + abs(pos[i-1].X - u) + abs(pos[i-1].Y - 2));
            }

            debug(i, u, d, dp[i][u]);
        }
    }

    cout << dp[n*2][n] << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 16120 KB Output is correct
2 Correct 13 ms 16120 KB Output is correct
3 Correct 13 ms 16120 KB Output is correct
4 Correct 13 ms 16120 KB Output is correct
5 Correct 14 ms 16120 KB Output is correct
6 Correct 15 ms 16120 KB Output is correct
7 Correct 13 ms 16120 KB Output is correct
8 Correct 13 ms 16120 KB Output is correct
9 Correct 13 ms 16124 KB Output is correct
10 Correct 13 ms 16120 KB Output is correct
11 Correct 14 ms 16120 KB Output is correct
12 Correct 13 ms 16120 KB Output is correct
13 Correct 14 ms 16120 KB Output is correct
14 Correct 13 ms 16120 KB Output is correct
15 Correct 13 ms 16120 KB Output is correct
16 Correct 13 ms 16120 KB Output is correct
17 Correct 13 ms 16120 KB Output is correct
18 Correct 13 ms 16124 KB Output is correct
19 Correct 13 ms 16120 KB Output is correct
20 Correct 13 ms 16124 KB Output is correct
21 Correct 13 ms 16120 KB Output is correct
22 Correct 13 ms 16120 KB Output is correct
23 Correct 13 ms 16120 KB Output is correct
24 Correct 14 ms 16120 KB Output is correct
25 Correct 13 ms 16120 KB Output is correct
26 Correct 13 ms 16120 KB Output is correct
27 Correct 14 ms 16120 KB Output is correct
28 Correct 13 ms 16120 KB Output is correct
29 Correct 13 ms 16120 KB Output is correct
30 Correct 14 ms 16124 KB Output is correct
31 Correct 13 ms 16120 KB Output is correct
32 Correct 13 ms 16120 KB Output is correct
33 Correct 13 ms 16120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 16120 KB Output is correct
2 Correct 13 ms 16120 KB Output is correct
3 Correct 13 ms 16120 KB Output is correct
4 Correct 13 ms 16120 KB Output is correct
5 Correct 14 ms 16120 KB Output is correct
6 Correct 15 ms 16120 KB Output is correct
7 Correct 13 ms 16120 KB Output is correct
8 Correct 13 ms 16120 KB Output is correct
9 Correct 13 ms 16124 KB Output is correct
10 Correct 13 ms 16120 KB Output is correct
11 Correct 14 ms 16120 KB Output is correct
12 Correct 13 ms 16120 KB Output is correct
13 Correct 14 ms 16120 KB Output is correct
14 Correct 13 ms 16120 KB Output is correct
15 Correct 13 ms 16120 KB Output is correct
16 Correct 13 ms 16120 KB Output is correct
17 Correct 13 ms 16120 KB Output is correct
18 Correct 13 ms 16124 KB Output is correct
19 Correct 13 ms 16120 KB Output is correct
20 Correct 13 ms 16124 KB Output is correct
21 Correct 13 ms 16120 KB Output is correct
22 Correct 13 ms 16120 KB Output is correct
23 Correct 13 ms 16120 KB Output is correct
24 Correct 14 ms 16120 KB Output is correct
25 Correct 13 ms 16120 KB Output is correct
26 Correct 13 ms 16120 KB Output is correct
27 Correct 14 ms 16120 KB Output is correct
28 Correct 13 ms 16120 KB Output is correct
29 Correct 13 ms 16120 KB Output is correct
30 Correct 14 ms 16124 KB Output is correct
31 Correct 13 ms 16120 KB Output is correct
32 Correct 13 ms 16120 KB Output is correct
33 Correct 13 ms 16120 KB Output is correct
34 Correct 20 ms 16120 KB Output is correct
35 Correct 20 ms 16120 KB Output is correct
36 Correct 20 ms 16120 KB Output is correct
37 Correct 20 ms 16124 KB Output is correct
38 Correct 20 ms 16120 KB Output is correct
39 Correct 21 ms 16120 KB Output is correct
40 Correct 20 ms 16248 KB Output is correct
41 Correct 20 ms 16120 KB Output is correct
42 Correct 21 ms 16120 KB Output is correct
43 Correct 20 ms 16120 KB Output is correct
44 Correct 21 ms 16248 KB Output is correct
45 Correct 20 ms 16120 KB Output is correct
46 Correct 20 ms 16120 KB Output is correct
47 Correct 20 ms 16120 KB Output is correct
48 Correct 20 ms 16120 KB Output is correct
49 Correct 21 ms 16120 KB Output is correct
50 Correct 20 ms 16120 KB Output is correct
51 Correct 20 ms 16120 KB Output is correct
52 Correct 20 ms 16120 KB Output is correct
53 Correct 20 ms 16120 KB Output is correct
54 Correct 20 ms 16120 KB Output is correct
55 Correct 21 ms 16120 KB Output is correct
56 Correct 20 ms 16120 KB Output is correct
57 Correct 20 ms 16120 KB Output is correct
58 Correct 20 ms 16248 KB Output is correct
59 Correct 20 ms 16120 KB Output is correct
60 Correct 20 ms 16120 KB Output is correct
61 Correct 20 ms 16120 KB Output is correct
62 Correct 20 ms 16120 KB Output is correct
63 Correct 20 ms 16120 KB Output is correct
64 Correct 20 ms 16124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 16120 KB Output is correct
2 Correct 13 ms 16120 KB Output is correct
3 Correct 13 ms 16120 KB Output is correct
4 Correct 13 ms 16120 KB Output is correct
5 Correct 14 ms 16120 KB Output is correct
6 Correct 15 ms 16120 KB Output is correct
7 Correct 13 ms 16120 KB Output is correct
8 Correct 13 ms 16120 KB Output is correct
9 Correct 13 ms 16124 KB Output is correct
10 Correct 13 ms 16120 KB Output is correct
11 Correct 14 ms 16120 KB Output is correct
12 Correct 13 ms 16120 KB Output is correct
13 Correct 14 ms 16120 KB Output is correct
14 Correct 13 ms 16120 KB Output is correct
15 Correct 13 ms 16120 KB Output is correct
16 Correct 13 ms 16120 KB Output is correct
17 Correct 13 ms 16120 KB Output is correct
18 Correct 13 ms 16124 KB Output is correct
19 Correct 13 ms 16120 KB Output is correct
20 Correct 13 ms 16124 KB Output is correct
21 Correct 13 ms 16120 KB Output is correct
22 Correct 13 ms 16120 KB Output is correct
23 Correct 13 ms 16120 KB Output is correct
24 Correct 14 ms 16120 KB Output is correct
25 Correct 13 ms 16120 KB Output is correct
26 Correct 13 ms 16120 KB Output is correct
27 Correct 14 ms 16120 KB Output is correct
28 Correct 13 ms 16120 KB Output is correct
29 Correct 13 ms 16120 KB Output is correct
30 Correct 14 ms 16124 KB Output is correct
31 Correct 13 ms 16120 KB Output is correct
32 Correct 13 ms 16120 KB Output is correct
33 Correct 13 ms 16120 KB Output is correct
34 Correct 20 ms 16120 KB Output is correct
35 Correct 20 ms 16120 KB Output is correct
36 Correct 20 ms 16120 KB Output is correct
37 Correct 20 ms 16124 KB Output is correct
38 Correct 20 ms 16120 KB Output is correct
39 Correct 21 ms 16120 KB Output is correct
40 Correct 20 ms 16248 KB Output is correct
41 Correct 20 ms 16120 KB Output is correct
42 Correct 21 ms 16120 KB Output is correct
43 Correct 20 ms 16120 KB Output is correct
44 Correct 21 ms 16248 KB Output is correct
45 Correct 20 ms 16120 KB Output is correct
46 Correct 20 ms 16120 KB Output is correct
47 Correct 20 ms 16120 KB Output is correct
48 Correct 20 ms 16120 KB Output is correct
49 Correct 21 ms 16120 KB Output is correct
50 Correct 20 ms 16120 KB Output is correct
51 Correct 20 ms 16120 KB Output is correct
52 Correct 20 ms 16120 KB Output is correct
53 Correct 20 ms 16120 KB Output is correct
54 Correct 20 ms 16120 KB Output is correct
55 Correct 21 ms 16120 KB Output is correct
56 Correct 20 ms 16120 KB Output is correct
57 Correct 20 ms 16120 KB Output is correct
58 Correct 20 ms 16248 KB Output is correct
59 Correct 20 ms 16120 KB Output is correct
60 Correct 20 ms 16120 KB Output is correct
61 Correct 20 ms 16120 KB Output is correct
62 Correct 20 ms 16120 KB Output is correct
63 Correct 20 ms 16120 KB Output is correct
64 Correct 20 ms 16124 KB Output is correct
65 Runtime error 119 ms 40544 KB Execution killed with signal 11 (could be triggered by violating memory limits)
66 Halted 0 ms 0 KB -