답안 #404144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
404144 2021-05-13T22:09:02 Z JerryLiu06 Plahte (COCI17_plahte) C++17
0 / 160
2000 ms 2984 KB
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using db = long double;
using str = string;
 
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
 
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
 
#define mp make_pair
#define f first
#define s second

#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
 
#define lb lower_bound
#define ub upper_bound
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)

const int MOD = 1e9 + 7;
const int MX = 1e5 + 10;
const ll INF = 1e18;

using pp = pair<pi, pi>;
using pip = pair<int, pl>;

int X, Y, N; vector<pp> R; set<pip> active; // {Y, {X, dist}}

map<pip, pip> par;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> X >> Y >> N; F0R(i, N) { 
        int X1, Y1, X2, Y2; cin >> X1 >> Y1 >> X2 >> Y2;

        if (X1 > X2) swap(X1, X2); if (Y1 > Y2) swap(Y1, Y2); 
        
        if (X1 <= X) R.pb({{X1, Y1}, {X2, Y2}});
    }
    sort(all(R)); active.insert({0, {0, 0}});
    
    EACH(P, R) {
        int X1 = P.f.f; int Y1 = P.f.s; int X2 = P.s.f; int Y2 = P.s.s;

        pip comp; comp = {Y1, {-INF, -INF}}; ll dTop = INF; ll dBot = INF; pip top, bot;

        while (active.lb(comp) != active.end()) {
            pip cur = *active.lb(comp); if (cur.f > Y2) break;

            ll D1 = cur.s.s + ((X1 - 1) - cur.s.f) + ((Y2 + 1) - cur.f);
            ll D2 = cur.s.s + ((X1 - 1) - cur.s.f) + (cur.f - (Y1 - 1));

            if (D1 < dTop) { dTop = D1; top = {Y2 + 1, {X1 - 1, D1}}; par[top] = cur; }
            if (D2 < dBot) { dBot = D2; bot = {Y1 - 1, {X1 - 1, D2}}; par[bot] = cur; }

            active.erase(cur);
        }
        if (dTop != INF && dBot != INF) active.insert(top), active.insert(bot);
    }
    ll res = INF; vector<pl> ans; pip last;
    
    EACH(P, active) if (res > P.s.s + abs(X - P.s.f) + abs(Y - P.f)) res = P.s.s + abs(X - P.s.f) + abs(Y - P.f), last = P;
    
    cout << res << "\n"; ans.pb({0, Y - last.f}); ans.pb({X - last.s.f, 0});

    while (last != pip{0, {0, 0}}) {
        pip cur = par[last]; ans.pb({0, last.f - cur.f}); ans.pb({last.s.f - cur.s.f, 0}); last = par[last];
    }
    int st = 0; if (ans.front() == pl{0, 0}) st = 1;
    
    cout << sz(ans) - st << "\n"; ROF(i, st, sz(ans)) cout << ans[i].f << " " << ans[i].s << "\n";
}

Compilation message

plahte.cpp: In function 'int main()':
plahte.cpp:61:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   61 |         if (X1 > X2) swap(X1, X2); if (Y1 > Y2) swap(Y1, Y2);
      |         ^~
plahte.cpp:61:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   61 |         if (X1 > X2) swap(X1, X2); if (Y1 > Y2) swap(Y1, Y2);
      |                                    ^~
plahte.cpp:68:45: warning: unused variable 'X2' [-Wunused-variable]
   68 |         int X1 = P.f.f; int Y1 = P.f.s; int X2 = P.s.f; int Y2 = P.s.s;
      |                                             ^~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2093 ms 2072 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 2072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2040 ms 2984 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 2500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 1532 KB Output isn't correct
2 Halted 0 ms 0 KB -