Submission #1295684

#TimeUsernameProblemLanguageResultExecution timeMemory
1295684baotoan655Coin Collecting (JOI19_ho_t4)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h>
#define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
using namespace std;

#define int long long
const int N = 1e5 + 5;
int n;
int a[2][N];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    file("A") else file("task");
    long long ans = 0;
    cin >> n;
    for(int i = 1; i <= 2 * n; ++i) {
        int x, y;
        cin >> x >> y;
        int dx = x, dy = y;
        if(x < 1) dx = 1;
        if(x > n) dx = n;
        if(y < 1) dy = 1;
        if(y > 2) dy = 2;
        ++a[dy][dx];
        ans += abs(x - dx) + abs(y - dy);
    }
    int s0 = 0, s1 = 0;
    for(int i = 1; i <= n; ++i) {
        s0 += a[0][i] - 1;
        s1 += a[1][i] - 1;
        if(s0 * s1 < 0) {
            if(s0 > s1) {
                int op = min(-s1, s0);
                ans += op;
                s0 -= op;
                s1 += op;
            } else {
               int op = min(-s0, s1);
                ans += op;
                s1 -= op;
                s0 += op;
            }
        }
        ans += abs(s0) + abs(s1);
    }
    cout << ans << '\n';
    return 0;
}

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int32_t main()':
joi2019_ho_t4.cpp:2:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:14:5: note: in expansion of macro 'file'
   14 |     file("A") else file("task");
      |     ^~~~
joi2019_ho_t4.cpp:2:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:14:5: note: in expansion of macro 'file'
   14 |     file("A") else file("task");
      |     ^~~~
joi2019_ho_t4.cpp:2:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:14:20: note: in expansion of macro 'file'
   14 |     file("A") else file("task");
      |                    ^~~~
joi2019_ho_t4.cpp:2:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:14:20: note: in expansion of macro 'file'
   14 |     file("A") else file("task");
      |                    ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...