Submission #682379

# Submission time Handle Problem Language Result Execution time Memory
682379 2023-01-16T07:30:27 Z vjudge1 Road Construction (JOI21_road_construction) C++17
13 / 100
5272 ms 86012 KB
#include "bits/stdc++.h"
using namespace std;

// #define ORD_SET
// #define ROPE
#ifdef ORD_SET
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    template<typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#endif
#ifdef ROPE
    #include <ext/rope>
    using namespace __gnu_cxx;
#endif        

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using ll = long long;
using ld = long double;
#define pb push_back
#define ff first
#define ss second
#define sz(x) (ll)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
// #define ll int
void freopen(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); }
void NotInteractive() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
void pre(ll a) { cout<<fixed<<setprecision(a); }
ll bit(ll x) { return __builtin_popcountll(x); }
ll binpow(ll x, ll y, ll z) { ll pow = 1; while(y) { if(y&1) pow *= x, pow %= z; x *= x, x %= z; y >>= 1; } return pow; }
template<typename T> T gcd(T a, T b) { if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b) { return a/gcd(a, b)*b; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

struct sn { ll l, r, x; }; // a.swap(b)
ll B = 316;
const ll mod = (ll)1e9+7;
const ll inf = (ll)1e18+7;
const ll MX = LLONG_MAX;
const ll MN = LLONG_MIN;
const ld P = acos(-1.0);
const ll N = (ll)3e5+5;
ll x[N], y[N];

void kigash() {
    ll n, k;
    cin>>n>>k;
    vector<pair<pair<ll, ll>, ll>> v;
    v.pb({{MN, MN}, MN});
    for(ll i=1; i<=n; i++) cin>>x[i]>>y[i], v.pb({{x[i], y[i]}, i});
    sort(all(v));
    set<pair<ll, pair<ll, ll>>> st, ts;
    for(ll i=1; i<=n; i++) {
        ll j = i+1;
        while(j<=n && sz(st)<k+1000) st.insert({abs(v[i].ff.ff-v[j].ff.ff)+abs(v[i].ff.ss-v[j].ff.ss), {v[i].ss, v[j].ss}}), j++;
        while(j<=n && (*st.rbegin()).ff>abs(v[i].ff.ff-v[j].ff.ff)+abs(v[i].ff.ss-v[j].ff.ss)) {
            st.erase(prev(st.end()));
            st.insert({abs(v[i].ff.ff-v[j].ff.ff)+abs(v[i].ff.ss-v[j].ff.ss), {v[i].ss, v[j].ss}});
            j++;
        }
    }
    v.clear();
    v.pb({{MN, MN}, MN});
    for(ll i=1; i<=n; i++) v.pb({{y[i], x[i]}, i});
    sort(all(v));
    for(ll i=1; i<=n; i++) {
        ll j = i+1;
        while(j<=n && sz(ts)<k+1000) ts.insert({abs(v[i].ff.ff-v[j].ff.ff)+abs(v[i].ff.ss-v[j].ff.ss), {v[i].ss, v[j].ss}}), j++;
        while(j<=n && (*ts.rbegin()).ff>abs(v[i].ff.ff-v[j].ff.ff)+abs(v[i].ff.ss-v[j].ff.ss)) {
            ts.erase(prev(ts.end()));
            ts.insert({abs(v[i].ff.ff-v[j].ff.ff)+abs(v[i].ff.ss-v[j].ff.ss), {v[i].ss, v[j].ss}});
            j++;
        }
    }
    map<pair<ll, ll>, ll> used;
    multiset<ll> ans;
    for(auto to:st) {
        ans.insert(to.ff);
        used[{to.ss.ff, to.ss.ss}] = used[{to.ss.ss, to.ss.ff}] = 1;
    }
    for(auto to:ts) {
        if(used[{to.ss.ff, to.ss.ss}]) continue;
        ans.insert(to.ff);
    }
    ll k1 = 0;
    for(auto x:ans) {
        k1++;
        cout<<x<<"\n";
        if(k1==k) break;
    }
    return;
}

signed main(/**/) {
    // freopen("");
    NotInteractive();
    // precalc();
    
    ll tt = 1;
    // cin>>tt;
    for(ll i=1; i<=tt; i++) kigash();
    
    exit(0);
}

Compilation message

road_construction.cpp: In function 'void freopen(std::string)':
road_construction.cpp:31:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 | void freopen(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); }
      |                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
road_construction.cpp:31:75: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 | void freopen(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); }
      |                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1471 ms 82784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4899 ms 85932 KB Output is correct
2 Correct 5272 ms 86012 KB Output is correct
3 Correct 997 ms 77012 KB Output is correct
4 Correct 4840 ms 85876 KB Output is correct
5 Correct 3877 ms 85964 KB Output is correct
6 Correct 3970 ms 86000 KB Output is correct
7 Correct 4149 ms 85260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 10496 KB Output is correct
2 Correct 105 ms 10492 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 89 ms 10376 KB Output is correct
5 Correct 113 ms 10508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 10496 KB Output is correct
2 Correct 105 ms 10492 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 89 ms 10376 KB Output is correct
5 Correct 113 ms 10508 KB Output is correct
6 Incorrect 109 ms 10412 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1471 ms 82784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1471 ms 82784 KB Output isn't correct
2 Halted 0 ms 0 KB -