답안 #682477

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682477 2023-01-16T09:23:26 Z vjudge1 Road Construction (JOI21_road_construction) C++17
100 / 100
3103 ms 18004 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/rope>
using namespace __gnu_cxx;

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


typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

#define precise(a) cout<<fixed<<setprecision(a)
#define sz size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
// t1
const ll mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6
const ll MOD = 998244353;  // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod
const ll N = ll(5e5)+10;
const ll K = 17;
const ll inf = 1e18;
const ld eps = 1e-15L;
//const ll B = 316;
ll lcm(ll a, ll b){ return (a / __gcd(a,b)) * b; }
//const ld P = acos(-1.0);

// ll binpow(ll a, ll b, ll m){ ll res=1;a%=m; while(b>0){ if(b&1)res=(res*a)%m; a=(a*a)%m; b/=2; } return res%m;}
ld binpow(ld a, ll b){ ld res=1; while(b>0){ if(b&1)res=(res*a); a=(a*a); b/=2; } return res;}


void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }


void precalc() {
}

ll getdis(ll x1, ll y1, ll x2, ll y2) {
    return abs(x2-x1)+abs(y2-y1);
}


void Baizho()
{   
    ll n, k; cin>>n>>k;
    pll a[n+11];
    ll sec = 2000;
    for(ll i=1; i<=n; i++) {
        cin>>a[i].ff>>a[i].ss;
    }
    sort(a+1, a+n+1);
    multiset<ll> st;
    for(ll i=1; i<=n-1; i++) {
        ll p = i;
        for(ll j = i+1; j<=i+sec && j<=n; j++) {
            // cout<<p<<" "<<j<<endl;
            ll x1 = a[p].ff, y1 = a[p].ss, x2 = a[j].ff, y2 = a[j].ss;
            ll dist = getdis(x1, y1, x2, y2);
            if(st.sz<k) st.insert(dist);
            else {
                if(*st.rbegin()>dist) {
                    st.erase(st.find(*st.rbegin()));
                    st.insert(dist);
                }
            }
        }
    }
    for(auto x : st) cout<<x<<"\n";

    
}

    
int main() {

    // Freopen("div7");
    ios_base::sync_with_stdio(false);   
    cin.tie(0);cout.tie(0); 

    precalc();

    int ttt = 1;
    // cin>>ttt;

    for(int i=1; i<=ttt; i++) { Baizho();}
}

Compilation message

road_construction.cpp: In function 'void Baizho()':
road_construction.cpp:64:21: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   64 |             if(st.sz<k) st.insert(dist);
      |                ~~~~~^~
road_construction.cpp: In function 'void Freopen(std::string)':
road_construction.cpp:37:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
      |                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
road_construction.cpp:37:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
      |                                                                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 273 ms 14520 KB Output is correct
2 Correct 286 ms 14628 KB Output is correct
3 Correct 129 ms 14668 KB Output is correct
4 Correct 139 ms 14696 KB Output is correct
5 Correct 216 ms 13508 KB Output is correct
6 Correct 4 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2897 ms 17112 KB Output is correct
2 Correct 2831 ms 17236 KB Output is correct
3 Correct 89 ms 14468 KB Output is correct
4 Correct 2744 ms 16972 KB Output is correct
5 Correct 2470 ms 17108 KB Output is correct
6 Correct 2365 ms 17228 KB Output is correct
7 Correct 2470 ms 16460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1551 ms 4212 KB Output is correct
2 Correct 1508 ms 4212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1521 ms 4212 KB Output is correct
5 Correct 1544 ms 4216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1551 ms 4212 KB Output is correct
2 Correct 1508 ms 4212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1521 ms 4212 KB Output is correct
5 Correct 1544 ms 4216 KB Output is correct
6 Correct 1504 ms 4328 KB Output is correct
7 Correct 1495 ms 4212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1499 ms 4340 KB Output is correct
11 Correct 1514 ms 4300 KB Output is correct
12 Correct 1511 ms 4208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 273 ms 14520 KB Output is correct
2 Correct 286 ms 14628 KB Output is correct
3 Correct 129 ms 14668 KB Output is correct
4 Correct 139 ms 14696 KB Output is correct
5 Correct 216 ms 13508 KB Output is correct
6 Correct 4 ms 436 KB Output is correct
7 Correct 1865 ms 15528 KB Output is correct
8 Correct 1842 ms 15524 KB Output is correct
9 Correct 120 ms 14672 KB Output is correct
10 Correct 1955 ms 14948 KB Output is correct
11 Correct 2581 ms 14756 KB Output is correct
12 Correct 1181 ms 15648 KB Output is correct
13 Correct 1389 ms 14076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 273 ms 14520 KB Output is correct
2 Correct 286 ms 14628 KB Output is correct
3 Correct 129 ms 14668 KB Output is correct
4 Correct 139 ms 14696 KB Output is correct
5 Correct 216 ms 13508 KB Output is correct
6 Correct 4 ms 436 KB Output is correct
7 Correct 2897 ms 17112 KB Output is correct
8 Correct 2831 ms 17236 KB Output is correct
9 Correct 89 ms 14468 KB Output is correct
10 Correct 2744 ms 16972 KB Output is correct
11 Correct 2470 ms 17108 KB Output is correct
12 Correct 2365 ms 17228 KB Output is correct
13 Correct 2470 ms 16460 KB Output is correct
14 Correct 1551 ms 4212 KB Output is correct
15 Correct 1508 ms 4212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1521 ms 4212 KB Output is correct
18 Correct 1544 ms 4216 KB Output is correct
19 Correct 1504 ms 4328 KB Output is correct
20 Correct 1495 ms 4212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1499 ms 4340 KB Output is correct
24 Correct 1514 ms 4300 KB Output is correct
25 Correct 1511 ms 4208 KB Output is correct
26 Correct 1865 ms 15528 KB Output is correct
27 Correct 1842 ms 15524 KB Output is correct
28 Correct 120 ms 14672 KB Output is correct
29 Correct 1955 ms 14948 KB Output is correct
30 Correct 2581 ms 14756 KB Output is correct
31 Correct 1181 ms 15648 KB Output is correct
32 Correct 1389 ms 14076 KB Output is correct
33 Correct 2937 ms 17996 KB Output is correct
34 Correct 2950 ms 18004 KB Output is correct
35 Correct 3103 ms 17228 KB Output is correct
36 Correct 2068 ms 17748 KB Output is correct
37 Correct 2084 ms 17876 KB Output is correct
38 Correct 2405 ms 16432 KB Output is correct