Submission #387890

# Submission time Handle Problem Language Result Execution time Memory
387890 2021-04-09T11:18:12 Z hackermub Road Construction (JOI21_road_construction) C++17
100 / 100
3083 ms 20144 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int,int>
#define float long double
#define pff pair<float,float>
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define uid uniform_int_distribution<int>
#define forn(i,st,n,inc) for(int i=st;i<n;i+=inc)
#define rforn(i,st,n,inc) for(int i=st-1;i>=n;i-=inc)
#define bruh cout<<"\nbruh\n"; return 0;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pi acos(-1)
const int MOD = 998244353;
const int64_t LLINF = 1e18+7;
const int32_t INF = 1e9+7;


ostream& operator<<(ostream& o,const string& s){
    for(auto c:s) o<<c;
    return o;
}

template<typename F,typename S>
ostream& operator<<(ostream& o,const pair<F,S>& p){
    o<<"["<<p.fi<<","<<p.se<<"]";
    return o;
}

template<typename... T,template<class...> class C>
ostream& operator<<(ostream& o,const C<T...>& v){
    o<<"[";
    int tot=0;
    for(auto x:v){ 
        o<<x;
        if(tot<v.size()-1) o<<",";
        tot++;
    }
    o<<"]";
    return o;
}

vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef OFFLINE
clock_t Tm=clock();
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...)
#endif

int dist(pii a,pii b){
    return abs(a.fi-b.fi)+abs(a.se-b.se);
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie();
    //If you hack my code , You are gay
    int n,k;
    cin>>n>>k;
    vector<pii> v(n);
    for(int i=0;i<n;i++) cin>>v[i].fi>>v[i].se;
    sort(all(v));
    multiset<int> st;
    int l,r;
    for(int i=1;i<n && k;i++){
        l=i,r=i;
        for(int j=i-1;j>=0 && k;j--){
            r--;
            st.insert(dist(v[i],v[j]));
            k--;
        }
    }
    debug(v);
    debug(st,l,r);
    int last=*--st.end();
    for(int i=l;i<n;i++){
        for(int j=r-1;j>=0;j--){
            if(last<=abs(v[i].fi-v[j].fi)) break;
            if(dist(v[i],v[j])<last){
                debug(j,i,dist(v[i],v[j]));
                st.erase(--st.end());
                st.insert(dist(v[i],v[j]));
                last=*--st.end();
            }
        }
        r=i+1;
    }
    for(auto x:st) cout<<x<<"\n";
    //mara kha
    #ifdef OFFLINE
        cerr<<"Time = "<<(double)(clock()-Tm)/CLOCKS_PER_SEC;
    #endif
    return 0;
}

Compilation message

road_construction.cpp: In function 'int32_t main()':
road_construction.cpp:88:9: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   88 |     int l,r;
      |         ^
road_construction.cpp:88:11: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   88 |     int l,r;
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 384 ms 14604 KB Output is correct
2 Correct 369 ms 14628 KB Output is correct
3 Correct 213 ms 14640 KB Output is correct
4 Correct 187 ms 14684 KB Output is correct
5 Correct 347 ms 13520 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1943 ms 20144 KB Output is correct
2 Correct 1815 ms 17116 KB Output is correct
3 Correct 154 ms 14552 KB Output is correct
4 Correct 1186 ms 16860 KB Output is correct
5 Correct 816 ms 17220 KB Output is correct
6 Correct 838 ms 17124 KB Output is correct
7 Correct 916 ms 16452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 4172 KB Output is correct
2 Correct 89 ms 4172 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 72 ms 4172 KB Output is correct
5 Correct 206 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 4172 KB Output is correct
2 Correct 89 ms 4172 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 72 ms 4172 KB Output is correct
5 Correct 206 ms 4172 KB Output is correct
6 Correct 91 ms 4120 KB Output is correct
7 Correct 91 ms 4172 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 94 ms 4172 KB Output is correct
11 Correct 70 ms 4224 KB Output is correct
12 Correct 208 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 384 ms 14604 KB Output is correct
2 Correct 369 ms 14628 KB Output is correct
3 Correct 213 ms 14640 KB Output is correct
4 Correct 187 ms 14684 KB Output is correct
5 Correct 347 ms 13520 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 2325 ms 17616 KB Output is correct
8 Correct 2247 ms 15588 KB Output is correct
9 Correct 209 ms 14788 KB Output is correct
10 Correct 2356 ms 14900 KB Output is correct
11 Correct 2802 ms 14764 KB Output is correct
12 Correct 606 ms 15540 KB Output is correct
13 Correct 1047 ms 14052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 384 ms 14604 KB Output is correct
2 Correct 369 ms 14628 KB Output is correct
3 Correct 213 ms 14640 KB Output is correct
4 Correct 187 ms 14684 KB Output is correct
5 Correct 347 ms 13520 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 1943 ms 20144 KB Output is correct
8 Correct 1815 ms 17116 KB Output is correct
9 Correct 154 ms 14552 KB Output is correct
10 Correct 1186 ms 16860 KB Output is correct
11 Correct 816 ms 17220 KB Output is correct
12 Correct 838 ms 17124 KB Output is correct
13 Correct 916 ms 16452 KB Output is correct
14 Correct 91 ms 4172 KB Output is correct
15 Correct 89 ms 4172 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 72 ms 4172 KB Output is correct
18 Correct 206 ms 4172 KB Output is correct
19 Correct 91 ms 4120 KB Output is correct
20 Correct 91 ms 4172 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 94 ms 4172 KB Output is correct
24 Correct 70 ms 4224 KB Output is correct
25 Correct 208 ms 4172 KB Output is correct
26 Correct 2325 ms 17616 KB Output is correct
27 Correct 2247 ms 15588 KB Output is correct
28 Correct 209 ms 14788 KB Output is correct
29 Correct 2356 ms 14900 KB Output is correct
30 Correct 2802 ms 14764 KB Output is correct
31 Correct 606 ms 15540 KB Output is correct
32 Correct 1047 ms 14052 KB Output is correct
33 Correct 3083 ms 17884 KB Output is correct
34 Correct 2935 ms 17884 KB Output is correct
35 Correct 3033 ms 17116 KB Output is correct
36 Correct 842 ms 17732 KB Output is correct
37 Correct 859 ms 17860 KB Output is correct
38 Correct 1397 ms 16452 KB Output is correct