Submission #902514

# Submission time Handle Problem Language Result Execution time Memory
902514 2024-01-10T14:15:27 Z jay_jayjay Coin Collecting (JOI19_ho_t4) C++17
37 / 100
156 ms 274432 KB
// {{{1
extern "C" int __lsan_is_turned_off() { return 1; }
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define inf 0x3f3f3f3f
#define infl 0x3f3f3f3f3f3f3f3fll

#include <assert.h>
#ifdef DEBUG
#define dprintf(args...) fprintf(stderr,args)
#endif
#ifndef DEBUG
#define dprintf(args...) 69
#endif
#define all(x) (x).begin(), (x).end()
// 1}}}

void chmin(ll& x, ll y) { x=min(x,y); }

int dist(array<int,2> a, array<int,2> b) {
        return abs(a[0]-b[0])+abs(a[1]-b[1]);
}

int main()
{
        int n;scanf("%d",&n);

        vector<array<int,2>> coins(2*n);
        for(auto&[x,y]:coins)scanf("%d%d",&x,&y);


        sort(all(coins));

        vector dp(n+1, vector<ll>(n+1,infl));


        dp[0][0]=0;
        for(int i=0;i<=n;i++)
                for(int j=0;j<=n;j++) {
                        if(i==n&&j==n) break;
                        auto coin = coins[i+j];

                        if(i<n)chmin(dp[i+1][j],dp[i][j]+dist(coin,{i+1,2}));
                        if(j<n)chmin(dp[i][j+1],dp[i][j]+dist(coin,{j+1,1}));
        }
        printf("%lld\n",dp[n][n]);
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:28:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         int n;scanf("%d",&n);
      |               ~~~~~^~~~~~~~~
joi2019_ho_t4.cpp:31:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         for(auto&[x,y]:coins)scanf("%d%d",&x,&y);
      |                              ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 428 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 436 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 356 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 416 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 428 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 436 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 356 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 416 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 8 ms 8280 KB Output is correct
35 Correct 9 ms 8284 KB Output is correct
36 Correct 11 ms 8280 KB Output is correct
37 Correct 8 ms 8280 KB Output is correct
38 Correct 9 ms 8284 KB Output is correct
39 Correct 9 ms 8132 KB Output is correct
40 Correct 8 ms 8292 KB Output is correct
41 Correct 8 ms 8284 KB Output is correct
42 Correct 8 ms 8360 KB Output is correct
43 Correct 8 ms 8284 KB Output is correct
44 Correct 8 ms 8284 KB Output is correct
45 Correct 9 ms 8284 KB Output is correct
46 Correct 9 ms 8280 KB Output is correct
47 Correct 8 ms 8284 KB Output is correct
48 Correct 8 ms 8284 KB Output is correct
49 Correct 10 ms 8292 KB Output is correct
50 Correct 11 ms 8284 KB Output is correct
51 Correct 8 ms 8284 KB Output is correct
52 Correct 8 ms 8280 KB Output is correct
53 Correct 8 ms 8284 KB Output is correct
54 Correct 8 ms 8292 KB Output is correct
55 Correct 8 ms 8288 KB Output is correct
56 Correct 8 ms 8156 KB Output is correct
57 Correct 9 ms 8288 KB Output is correct
58 Correct 11 ms 8296 KB Output is correct
59 Correct 8 ms 8292 KB Output is correct
60 Correct 8 ms 8296 KB Output is correct
61 Correct 8 ms 8292 KB Output is correct
62 Correct 8 ms 8356 KB Output is correct
63 Correct 11 ms 8280 KB Output is correct
64 Correct 8 ms 8128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 428 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 436 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 356 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 416 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 8 ms 8280 KB Output is correct
35 Correct 9 ms 8284 KB Output is correct
36 Correct 11 ms 8280 KB Output is correct
37 Correct 8 ms 8280 KB Output is correct
38 Correct 9 ms 8284 KB Output is correct
39 Correct 9 ms 8132 KB Output is correct
40 Correct 8 ms 8292 KB Output is correct
41 Correct 8 ms 8284 KB Output is correct
42 Correct 8 ms 8360 KB Output is correct
43 Correct 8 ms 8284 KB Output is correct
44 Correct 8 ms 8284 KB Output is correct
45 Correct 9 ms 8284 KB Output is correct
46 Correct 9 ms 8280 KB Output is correct
47 Correct 8 ms 8284 KB Output is correct
48 Correct 8 ms 8284 KB Output is correct
49 Correct 10 ms 8292 KB Output is correct
50 Correct 11 ms 8284 KB Output is correct
51 Correct 8 ms 8284 KB Output is correct
52 Correct 8 ms 8280 KB Output is correct
53 Correct 8 ms 8284 KB Output is correct
54 Correct 8 ms 8292 KB Output is correct
55 Correct 8 ms 8288 KB Output is correct
56 Correct 8 ms 8156 KB Output is correct
57 Correct 9 ms 8288 KB Output is correct
58 Correct 11 ms 8296 KB Output is correct
59 Correct 8 ms 8292 KB Output is correct
60 Correct 8 ms 8296 KB Output is correct
61 Correct 8 ms 8292 KB Output is correct
62 Correct 8 ms 8356 KB Output is correct
63 Correct 11 ms 8280 KB Output is correct
64 Correct 8 ms 8128 KB Output is correct
65 Runtime error 156 ms 274432 KB Execution killed with signal 9
66 Halted 0 ms 0 KB -