Submission #239778

# Submission time Handle Problem Language Result Execution time Memory
239778 2020-06-17T09:36:46 Z Vimmer Priglavci (COCI18_priglavci) C++14
16 / 160
2000 ms 384 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];

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

bool mk[105];

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);

    int n, m, c, k;

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

    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;}
    }

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

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
          mn[i][id[j]] = min(mn[i][id[j]], rst(cx[i], cy[i], sx[j], sy[j]));

    int ans = 0;

    while (1)
    {
        int v = -1, val, t;

        for (int i = 0; i < n; i++)
        {
            if (a[i] != 0) continue;

            int mnr = 1e9, tr = -1;

            for (int j = 1; j <= k; j++) if (!mk[j] && mnr > mn[i][j]) {mnr = mn[i][j]; tr = j;}

            if (v == -1 || val < mnr) {val = mnr; v = i; t = tr;}
        }

        if (v == -1) continue;

        if (t == -1) {cout << -1 << endl; exit(0);}

        mk[t] = 1;

        a[v] = t;

        ans += val;
    }

    cout << ans << endl;

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

Compilation message

priglvaci.cpp: In function 'int main()':
priglvaci.cpp:99:14: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
         a[v] = t;
         ~~~~~^~~
priglvaci.cpp:90:32: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]
             if (v == -1 || val < mnr) {val = mnr; v = i; t = tr;}
                            ~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 384 KB Time limit exceeded
2 Execution timed out 2090 ms 384 KB Time limit exceeded
3 Correct 5 ms 384 KB Output is correct
4 Execution timed out 2090 ms 384 KB Time limit exceeded
5 Execution timed out 2090 ms 384 KB Time limit exceeded
6 Incorrect 5 ms 384 KB Output isn't correct
7 Incorrect 5 ms 384 KB Output isn't correct
8 Execution timed out 2090 ms 384 KB Time limit exceeded
9 Incorrect 5 ms 384 KB Output isn't correct
10 Incorrect 5 ms 384 KB Output isn't correct