답안 #825599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
825599 2023-08-15T05:57:39 Z xink Road Construction (JOI21_road_construction) C++14
5 / 100
118 ms 6788 KB
#include <iostream>
#include <vector>
#include <utility>
#include <sstream>
#include <climits>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <assert.h>
#define ll long long
#define ld long double
using namespace std;
const ll mod = 1e9 + 7;
typedef vector<int> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
const int maxn1 = 2e5 + 5, maxn2 = 1e6 + 6;
ii coor[maxn1];
ll dist[maxn2];

ll get_manhattan_dist(int i, int j)
{
    return abs(coor[i].first - coor[j].first) + abs(coor[i].second - coor[j].second);
}

void solve_sub1(int n, int k)
{
    int n_road = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < i; j++)
        {
            dist[n_road++] = get_manhattan_dist(i, j);
        }
    }
    sort(dist, dist + n_road);
    for (int i = 0; i < k; i++)
    {
        cout << dist[i] << "\n";
    }
}

void solve_sub2(int n, ll k)
{
    sort(coor, coor + n);
    ll l = 1, r = coor[n - 1].first - coor[0].first;
    // while (l < r)
    // {
    //     int m = (l + r) >> 1, l1 = 0;
    //     ll cnt = 0;
    //     for (int i = 0; i < n; i++)
    //     {
    //         while (l1 < i && get_manhattan_dist(l1, i) > m)
    //         {
    //             l1++;
    //         }
    //         cnt += i - l1;
    //     }
    //     if (cnt >= k)
    //     {
    //         r = m;
    //     }
    //     else
    //     {
    //         l = m + 1;
    //     }
    // }
    int n_road = 0, lp = 0;
    // for (int i = 0; i < n; i++)
    // {
    //     while (lp < i && get_manhattan_dist(lp, i) >= l)
    //     {
    //         lp++;
    //     }
    //     for (int j = lp; j < i; j++)
    //     {
    //         dist[n_road++] = get_manhattan_dist(j, i);
    //     }
    // }
    assert(n_road <= k);
    for (int i = n_road; i < k; i++)
    {
        dist[i] = l;
    }
    sort(dist, dist + k);
    for (int i = 0; i < k; i++)
    {
        cout << dist[i] << '\n';
    }
}

void solve()
{
    int n, k;
    cin >> n >> k;
    bool all_y0 = 1;
    for (int i = 0; i < n; i++)
    {
        cin >> coor[i].first >> coor[i].second;
        all_y0 &= (coor[i].second == 0);
    }
    if (n <= 1000)
    {
        solve_sub1(n, k);
        return;
    }
    if (all_y0)
    {
        solve_sub2(n, k);
        return;
    }
}

int main()
{
    // freopen("input_text", "r", stdin);
    // freopen("output_text", "w", stdout);
    // ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t-- > 0)
        solve();
}

Compilation message

road_construction.cpp: In function 'void solve_sub2(int, long long int)':
road_construction.cpp:46:15: warning: unused variable 'r' [-Wunused-variable]
   46 |     ll l = 1, r = coor[n - 1].first - coor[0].first;
      |               ^
road_construction.cpp:68:21: warning: unused variable 'lp' [-Wunused-variable]
   68 |     int n_road = 0, lp = 0;
      |                     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 6788 KB Output is correct
2 Correct 56 ms 6788 KB Output is correct
3 Correct 36 ms 4852 KB Output is correct
4 Correct 34 ms 4856 KB Output is correct
5 Correct 48 ms 5636 KB Output is correct
6 Correct 18 ms 4180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 81 ms 6672 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 118 ms 6688 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 118 ms 6688 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 6788 KB Output is correct
2 Correct 56 ms 6788 KB Output is correct
3 Correct 36 ms 4852 KB Output is correct
4 Correct 34 ms 4856 KB Output is correct
5 Correct 48 ms 5636 KB Output is correct
6 Correct 18 ms 4180 KB Output is correct
7 Incorrect 60 ms 1792 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 6788 KB Output is correct
2 Correct 56 ms 6788 KB Output is correct
3 Correct 36 ms 4852 KB Output is correct
4 Correct 34 ms 4856 KB Output is correct
5 Correct 48 ms 5636 KB Output is correct
6 Correct 18 ms 4180 KB Output is correct
7 Runtime error 81 ms 6672 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -