답안 #239941

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
239941 2020-06-17T14:53:33 Z Vimmer Priglavci (COCI18_priglavci) C++14
80 / 160
13 ms 896 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 101001
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9


using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef short int si;
typedef array <int, 3> a3;

//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;



int id[105], a[105];

int mn[105][105], number[105][105], n, m, c, k;

ll limit;

set <int> se[105];

int rst(int x, int y, int cx, int cy) {return (cx - x) * (cx - x) + (cy - y) * (cy - y);}

set <pair <int, int> > g[105];

bool mk[105];

bool kuna(int v);

bool can(int v)
{
    for (auto it : se[v])
        if (kuna(it)) {se[v].erase(it); return 1;}

    return 0;
}
bool kuna(int v)
{
    if (mk[v]) return 0;

    mk[v] = 1;

    for (auto it : g[v])
        if (it.F <= limit && (sz(se[it.S]) < c) || can(it.S))
            {
                se[it.S].insert(v);

                return 1;
            }

    return 0;
}

bool gd()
{
    memset(a, 0, sizeof(a));

    for (int i = 1; i <= k; i++) se[i].clear();

    for (int i = 0; i < n; i++)
    {
        memset(mk, 0, sizeof(mk));

        kuna(i);
    }

    for (int i = 1; i <= k; i++) for (auto it : se[i]) a[it] = i;

    for (int i = 0; i < n; i++) if (a[i] == 0) return 0;

    return 1;
}
int main()
{
    //freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m >> c >> k;

    if (c * k < n) {cout << -1 << endl; exit(0);}

    int cx[n], cy[n];

    for (int i = 0; i < n; i++) cin >> cx[i] >> cy[i];

    for (int i = 0; i < 105; i++)
        for (int j = 0; j < 105; j++) mn[i][j] = 1e9;

    int sx[m], sy[m];

    for (int i = 0; i < m; i++) cin >> sx[i] >> sy[i];

    for (int i = 1; i <= k; i++)
    {
        int kol;

        cin >> kol;

        for (; kol > 0; kol--) {int x; cin >> x; x--; id[x] = i;}
    }

    vector <int> values; values.clear();

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
          {ll rast = rst(cx[i], cy[i], sx[j], sy[j]); if (mn[i][id[j]] > rast) {mn[i][id[j]] = rast; number[i][id[j]] = j + 1;} values.pb(rast);}

    for (int i = 0; i < n; i++)
        for (int j = 1; j <= k; j++)
          g[i].insert({mn[i][j], j});

    sort(values.begin(), values.end());

    int l = 0, r = sz(values) - 1;

    while (l + 1 < r)
    {
        int md = (l + r) >> 1;

        limit = values[md];

        if (gd()) r = md; else l = md;
    }

    limit = values[l];

    while (gd() && l >= 0) {l--; if (l != -1) limit = values[l];};

    l++;

    limit = values[l];

    gd();

    cout << limit << endl;

    for (int i = 0; i < n; i++) cout << number[i][a[i]] << endl;
}

Compilation message

priglvaci.cpp: In function 'bool kuna(int)':
priglvaci.cpp:62:27: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
         if (it.F <= limit && (sz(se[it.S]) < c) || can(it.S))
             ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Failed 8 ms 640 KB the weakness doesn't match with your distribution
2 Failed 6 ms 512 KB the weakness doesn't match with your distribution
3 Correct 4 ms 384 KB Output is correct
4 Failed 13 ms 768 KB the weakness doesn't match with your distribution
5 Failed 9 ms 768 KB the weakness doesn't match with your distribution
6 Correct 6 ms 896 KB Output is correct
7 Incorrect 5 ms 512 KB Integer 0 violates the range [1, 25]
8 Correct 5 ms 512 KB Output is correct
9 Correct 7 ms 768 KB Output is correct
10 Correct 6 ms 564 KB Output is correct