답안 #966499

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966499 2024-04-20T02:01:09 Z Pring Palembang Bridges (APIO15_bridge) C++17
0 / 100
1 ms 604 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;

const int MXN = 100005;
int n, k;
vector<pii> v;
ll sum;

struct SLOPE_TRICK {
    int val, now;
    multiset<int> L, R;
    void init() {
        val = 0;
        now = INT_MAX;
        L.clear();
        R.clear();
        L.insert(INT_MIN);
        R.insert(INT_MAX);
    }
    void add(int x) {
        val += abs(now - x);
        if (L.lower_bound(x) == L.end()) {
            if (x <= *R.begin()) {
                L.insert(x);
                R.insert(x);
                val -= abs(now - x);
                now = x;
            } else {
                R.insert(x);
                R.insert(x);
                L.insert(*R.begin());
                R.erase(R.begin());
                now = *R.begin();
            }
        } else {
            L.insert(x);
            L.insert(x);
            R.insert(*L.rbegin());
            L.erase(prev(L.end()));
            int cur = *R.begin();
            val -= (now - cur);
            now = cur;
        }
    }
    void COUT() {
        debug(now, val);
        for (auto i : L) cout << i << ' ';
        cout << endl;
        for (auto i : R) cout << i << ' ';
        cout << endl;
    }
} slt;

void miku() {
    cin >> k >> n;
    assert(k == 1);
    FOR(i, 0, n) {
        int a, b;
        char c, d;
        cin >> c >> a >> d >> b;
        if (a > b) swap(a, b);
        if (c == d) {
            sum += b - a;
        } else {
            sum += 1;
            v.push_back(mp(a, b));
        }
    }
    slt.init();
    for (auto &[a, b] : v) {
        slt.add(a);
        // slt.COUT();
        slt.add(b);
        // slt.COUT();
    }
    cout << sum + slt.val << '\n';
}

void test() {
    slt.init();
    slt.add(0);
    slt.COUT();
    slt.add(1);
    slt.COUT();
    slt.add(2);
    slt.COUT();
    slt.add(3);
    slt.COUT();
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    miku();
    return 0;
}

Compilation message

bridge.cpp: In member function 'void SLOPE_TRICK::COUT()':
bridge.cpp:11:20: warning: statement has no effect [-Wunused-value]
   11 | #define debug(...) 39
      |                    ^~
bridge.cpp:63:9: note: in expansion of macro 'debug'
   63 |         debug(now, val);
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Incorrect 1 ms 604 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Incorrect 1 ms 604 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -