답안 #527071

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527071 2022-02-16T21:53:11 Z AdamGS Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 328 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
const int LIM=1e5+7, K=5;
const ll INF=1e18+7;
ll ile[LIM][2], dp[LIM][2*K+1];
vector<pair<ll,ll>>V;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin >> n;
    ll ans=0;
    rep(i, 2*n) {
        ll a, b;
        cin >> a >> b;
        ans+=max(1-a, 0ll);
        a=max(a, 1ll);
        ans+=max(a-n, 0ll);
        a=min(a, n);
        ans+=max(1-b, 0ll);
        b=max(b, 1ll);
        ans+=max(b-2, 0ll);
        b=min(b, 2ll);
        --a; --b;
        ++ile[a][b];
    }
    rep(i, n) {
        while(ile[i][0] && ile[i][1]) {
            V.pb({i, 0});
            V.pb({i, 1});
            --ile[i][0];
            --ile[i][1];
        }
        while(ile[i][0]) {
            V.pb({i, 0});
            --ile[i][0];
        }
        while(ile[i][1]) {
            V.pb({i, 1});
            --ile[i][1];
        }
    }
    rep(i, V.size()+1) rep(j, 2*K+1) dp[i][j]=INF;
    dp[0][K]=0;
    rep(i, V.size()) {
        rep(j, 2*K+1) {
            if((i+1+j-K)%2) continue;
            ll x=(i+1+j-K)/2-1;
            if(j) {
                dp[i+1][j]=min(dp[i+1][j], dp[i][j-1]+abs(V[i].nd-0ll)+abs(V[i].st-x));
            }
            if(j<2*K) {
                dp[i+1][j]=min(dp[i+1][j], dp[i][j+1]+abs(V[i].nd-1ll)+abs(V[i].st-(x-j+K)));
            }
        }
    }
    cout << ans+dp[V.size()][K] << '\n';
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
joi2019_ho_t4.cpp:47:5: note: in expansion of macro 'rep'
   47 |     rep(i, V.size()+1) rep(j, 2*K+1) dp[i][j]=INF;
      |     ^~~
joi2019_ho_t4.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
joi2019_ho_t4.cpp:49:5: note: in expansion of macro 'rep'
   49 |     rep(i, V.size()) {
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 0 ms 320 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 0 ms 328 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 0 ms 320 KB Output is correct
23 Correct 0 ms 208 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Incorrect 1 ms 208 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 0 ms 320 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 0 ms 328 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 0 ms 320 KB Output is correct
23 Correct 0 ms 208 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Incorrect 1 ms 208 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 0 ms 320 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 1 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 0 ms 328 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 1 ms 208 KB Output is correct
21 Correct 1 ms 208 KB Output is correct
22 Correct 0 ms 320 KB Output is correct
23 Correct 0 ms 208 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 324 KB Output is correct
27 Correct 1 ms 208 KB Output is correct
28 Incorrect 1 ms 208 KB Output isn't correct
29 Halted 0 ms 0 KB -