답안 #878985

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878985 2023-11-26T03:03:52 Z niter Coin Collecting (JOI19_ho_t4) C++14
100 / 100
38 ms 6068 KB
#include <bits/stdc++.h>
#define pb push_back
#define ins isnert
#define pii pair<int,int>
#define ff first
#define ss second
#define loop(i,a,b) for(int i = (a); i < (b); i ++)
#define op(x) cerr << #x << " = " << x << endl;
#define opa(x) cerr << #x << " = " << x << ", ";
#define ops(x) cerr << x;
#define spac cerr << ' ';
#define entr cerr << endl;
#define STL(x) cerr << #x << " : "; for(auto &qwe:x) cerr << qwe << ' '; cerr << endl;
#define ARR(x, nnn) cerr << #x << " : "; loop(qwe,0,nnn) cerr << x[qwe] << ' '; cerr << endl;
#define BAE(x) (x).begin(), (x).end()
#define bye exit(0);
using namespace std;
typedef long long ll;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());

//ostream& operator<<(ostream &os, pair<int, char> x){
//    os << "[" << x.ff << ", " << x.ss << "]";
//}
const int mxn = (int)(1e5) + 10;
int dp[mxn][2];

void show(int n){
    loop(j,1,3){
        loop(i,1,n+1){
            cout << dp[i][3-j] << ' ';
        }
        cout << endl;
    }
}
int main(){
    ios::sync_with_stdio(false); cin.tie(0);
//    freopen("in.txt", "r", stdin);
    int n, m;
    cin >> n;
    m = n << 1;
    ll ans = 0;
    loop(i,1,n+1){
        loop(j,1,3){
            dp[i][j]++;
        }
    }
    loop(i,0,m){
        int x, y;
        cin >> x >> y;
        if(y >= 2){
            ans += y - 2;
            if(x <= 1){
                ans += 1 - x;
                dp[1][2]--;
            }
            else if(x >= n){
                ans += x - n;
                dp[n][2]--;
            }
            else{
                dp[x][2]--;
            }
        }
        else{
            ans += 1 - y;
            if(x <= 1){
                ans += 1 - x;
                dp[1][1]--;
            }
            else if(x >= n){
                ans += x - n;
                dp[n][1]--;
            }
            else{
                dp[x][1]--;
            }
        }
    }
//    op(ans)
//    show(n);
    loop(i,1,n+1){
        // don't lend / borrow too much
        if(dp[i][1] > 0 && dp[i][2] < 0){
            int trans = min(abs(dp[i][1]), abs(dp[i][2]));
            ans += trans;
            dp[i][1] -= trans;
            dp[i][2] += trans;
        }
        else if(dp[i][1] < 0 && dp[i][2] > 0){
            int trans = min(abs(dp[i][1]), abs(dp[i][2]));
            ans += trans;
            dp[i][1] += trans;
            dp[i][2] -= trans;
        }
        // lend from next row
        loop(j,1,3){
            dp[i+1][j] += dp[i][j];
            ans += abs(dp[i][j]);
            dp[i][j] -= dp[i][j];
        }
//        op(ans)
//        show(n);
    }
    cout << ans;
}
/*
*/

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:44:20: warning: iteration 1 invokes undefined behavior [-Waggressive-loop-optimizations]
   44 |             dp[i][j]++;
      |             ~~~~~~~^
joi2019_ho_t4.cpp:7:40: note: within this loop
    7 | #define loop(i,a,b) for(int i = (a); i < (b); i ++)
      |                                        ^
joi2019_ho_t4.cpp:43:9: note: in expansion of macro 'loop'
   43 |         loop(j,1,3){
      |         ^~~~
joi2019_ho_t4.cpp:97:24: warning: iteration 1 invokes undefined behavior [-Waggressive-loop-optimizations]
   97 |             dp[i+1][j] += dp[i][j];
      |             ~~~~~~~~~~~^~~~~~~~~~~
joi2019_ho_t4.cpp:7:40: note: within this loop
    7 | #define loop(i,a,b) for(int i = (a); i < (b); i ++)
      |                                        ^
joi2019_ho_t4.cpp:96:9: note: in expansion of macro 'loop'
   96 |         loop(j,1,3){
      |         ^~~~
joi2019_ho_t4.cpp:44:20: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   44 |             dp[i][j]++;
      |             ~~~~~~~^
joi2019_ho_t4.cpp:44:20: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
joi2019_ho_t4.cpp:61:24: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   61 |                 dp[x][2]--;
      |                 ~~~~~~~^
joi2019_ho_t4.cpp:61:24: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
joi2019_ho_t4.cpp:58:24: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   58 |                 dp[n][2]--;
      |                 ~~~~~~~^
joi2019_ho_t4.cpp:58:24: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
joi2019_ho_t4.cpp:54:24: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   54 |                 dp[1][2]--;
      |                 ~~~~~~~^
joi2019_ho_t4.cpp:54:24: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
joi2019_ho_t4.cpp:83:35: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   83 |         if(dp[i][1] > 0 && dp[i][2] < 0){
      |                            ~~~~~~~^
joi2019_ho_t4.cpp:87:22: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   87 |             dp[i][2] += trans;
      |             ~~~~~~~~~^~~~~~~~
joi2019_ho_t4.cpp:89:40: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   89 |         else if(dp[i][1] < 0 && dp[i][2] > 0){
      |                                 ~~~~~~~^
joi2019_ho_t4.cpp:93:22: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   93 |             dp[i][2] -= trans;
      |             ~~~~~~~~~^~~~~~~~
joi2019_ho_t4.cpp:97:24: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   97 |             dp[i+1][j] += dp[i][j];
      |             ~~~~~~~~~~~^~~~~~~~~~~
joi2019_ho_t4.cpp:97:34: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   97 |             dp[i+1][j] += dp[i][j];
      |                           ~~~~~~~^
joi2019_ho_t4.cpp:97:24: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   97 |             dp[i+1][j] += dp[i][j];
      |             ~~~~~~~~~~~^~~~~~~~~~~
joi2019_ho_t4.cpp:98:31: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   98 |             ans += abs(dp[i][j]);
      |                        ~~~~~~~^
joi2019_ho_t4.cpp:99:22: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   99 |             dp[i][j] -= dp[i][j];
      |             ~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 472 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 472 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 348 KB Output is correct
22 Correct 0 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 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 472 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 472 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 348 KB Output is correct
22 Correct 0 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 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 484 KB Output is correct
39 Correct 1 ms 484 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 508 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 476 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 484 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 1 ms 504 KB Output is correct
64 Correct 1 ms 756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 472 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 600 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 472 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 348 KB Output is correct
22 Correct 0 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 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 484 KB Output is correct
39 Correct 1 ms 484 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 508 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 476 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 484 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 1 ms 504 KB Output is correct
64 Correct 1 ms 756 KB Output is correct
65 Correct 20 ms 2760 KB Output is correct
66 Correct 38 ms 6068 KB Output is correct
67 Correct 30 ms 4408 KB Output is correct
68 Correct 29 ms 4188 KB Output is correct
69 Correct 29 ms 4164 KB Output is correct
70 Correct 29 ms 4188 KB Output is correct
71 Correct 29 ms 4176 KB Output is correct
72 Correct 28 ms 4180 KB Output is correct
73 Correct 31 ms 4424 KB Output is correct
74 Correct 28 ms 4180 KB Output is correct
75 Correct 28 ms 4180 KB Output is correct
76 Correct 28 ms 4420 KB Output is correct
77 Correct 28 ms 4180 KB Output is correct
78 Correct 28 ms 4436 KB Output is correct
79 Correct 28 ms 4176 KB Output is correct
80 Correct 29 ms 4176 KB Output is correct
81 Correct 37 ms 4180 KB Output is correct
82 Correct 29 ms 4408 KB Output is correct
83 Correct 28 ms 4176 KB Output is correct
84 Correct 28 ms 4188 KB Output is correct
85 Correct 28 ms 4188 KB Output is correct
86 Correct 28 ms 4172 KB Output is correct
87 Correct 38 ms 4404 KB Output is correct
88 Correct 28 ms 4184 KB Output is correct
89 Correct 28 ms 4188 KB Output is correct
90 Correct 29 ms 4176 KB Output is correct
91 Correct 29 ms 4184 KB Output is correct
92 Correct 28 ms 4432 KB Output is correct
93 Correct 28 ms 4436 KB Output is correct
94 Correct 27 ms 4188 KB Output is correct
95 Correct 27 ms 4188 KB Output is correct
96 Correct 28 ms 4432 KB Output is correct
97 Correct 29 ms 4432 KB Output is correct
98 Correct 28 ms 4432 KB Output is correct
99 Correct 28 ms 4180 KB Output is correct
100 Correct 28 ms 4436 KB Output is correct
101 Correct 28 ms 4188 KB Output is correct
102 Correct 28 ms 4296 KB Output is correct
103 Correct 28 ms 4180 KB Output is correct