답안 #873118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
873118 2023-11-14T13:32:47 Z hct_2so1 Coin Collecting (JOI19_ho_t4) C++17
0 / 100
0 ms 460 KB
#include <bits/stdc++.h>

#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define F first
#define S second
#define pii(x, y) make_pair(x, y)
#define __builtin_popcount __builtin_popcountll
#define __builtin_ctz __builtin_ctzll
#define __builtin_clz __builtin_clzll
#define lg(x) (63 - __builtin_clz(x))

template <class X, class Y>
    bool minimize(X &x, const Y &y)
    {
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y)
    {
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }

using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
const int M = 6e5;
const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const ll oo = 2e18;
const double eps = 1e-1;

int n, c[2][N];
pair<int, int> a[N];

void Input(void)
{
    cin >> n;
    for (int i = 1; i <= 2 * n; i ++) cin >> a[i].S >> a[i].F;
}

void solve(void)
{
    ll ans = 0;
    for (int i = 1; i <= 2 * n; i ++)
    {
        if (a[i].F < 1) ans += 1 - a[i].F, a[i].F = 1;
        if (a[i].F > 2) ans += a[i].F - 2, a[i].F = 2;
        if (a[i].S < 1) ans += 1 - a[i].S, a[i].S = 1;
        if (a[i].S > n) ans += a[i].S - n, a[i].S = n;
        c[a[i].F][a[i].S] ++;
    }
    int row[] = {0, 0, 0};
    for (int i = 1; i <= n; i ++)
    {
        c[1][i] --, c[2][i] --;
        row[1] += c[1][i];
        row[2] += c[2][i];
        if (row[1] < 0 && row[2] > 0)
        {
            int k = min(-row[1], row[2]);
            ans += k;
            row[1] += k;
            row[2] -= k;
        }
        else
            if (row[1] > 0 && row[2] < 0)
            {
                int k = min(row[1], -row[2]);
                ans += k;
                row[1] -= k;
                row[2] += k;
            }
        ans += abs(row[1]) + abs(row[2]);
    }
    cout << ans;
}

int main()
{
    std::ios_base::sync_with_stdio(0); cin.tie(0);
//    freopen("CLASSROOM.inp", "r", stdin);
//    freopen("CLASSROOM.out", "w", stdout);
    int test = 1;
    //cin >> test;
    while (test --)
    {
        Input();
        solve();
    }
    return 0;
}

Compilation message

joi2019_ho_t4.cpp: In function 'void solve()':
joi2019_ho_t4.cpp:64:24: warning: array subscript 2 is above array bounds of 'int [2][100005]' [-Warray-bounds]
   64 |         c[1][i] --, c[2][i] --;
      |                     ~~~^
joi2019_ho_t4.cpp:41:8: note: while referencing 'c'
   41 | int n, c[2][N];
      |        ^
joi2019_ho_t4.cpp:64:24: warning: array subscript 2 is above array bounds of 'int [2][100005]' [-Warray-bounds]
   64 |         c[1][i] --, c[2][i] --;
      |                     ~~~^
joi2019_ho_t4.cpp:41:8: note: while referencing 'c'
   41 | int n, c[2][N];
      |        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 460 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 460 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 460 KB Output isn't correct
5 Halted 0 ms 0 KB -