Submission #173487

# Submission time Handle Problem Language Result Execution time Memory
173487 2020-01-04T09:13:57 Z Tuk1352 Countries (BOI06_countries) C++11
100 / 100
11 ms 504 KB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, I;
    cin >> n;
    long double X[n], Y[n], s[n], d, M, D;
    int C[n], Im, k;
    vector <pair<int,int>> V;
    for (int i = 0; i < n; i++)
    {
        cin >> X[i] >> Y[i] >> s[i];
        V.push_back({s[i],i});
    }
    sort(V.rbegin(),V.rend());
    for (int i = 0; i < V.size(); i++)
    {
        I = V[i].second;
        Im = I;
        M = 0;
        k = 0;
        D = 1;
        for (int y = 0; y < n; y++)
        {
            if (I != y)
            {
                d = ((X[I]-X[y])*(X[I]-X[y])+(Y[I]-Y[y])*(Y[I]-Y[y]));
                if (s[y]/d > s[I])
                {
                    if (s[y]/d > s[Im]/D)
                    {
                        //M = s[y]/d;
                        D = d;
                        k = 1;
                        Im = y;
                    }
                    else if (fabs(s[y]/d-s[Im]/D) <= 0.000000001 && C[y] != Im)
                    {
                        k++;
                    }
                }
            }
        }
        if (k == 0)
        {
            C[I] = I;
        }
        else if (k != 1)
        {
            C[I] = -1;
        }
        else
        {
            C[I] = C[Im];
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (C[i] == i)
        {
            cout << "K" << "\n";
        }
        else if (C[i] == -1)
        {
            cout << "D" << "\n";
        }
        else
        {
            cout << C[i]+1 << "\n";
        }
    }
    return 0;
}

Compilation message

countries.cpp: In function 'int main()':
countries.cpp:18:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < V.size(); i++)
                     ~~^~~~~~~~~~
countries.cpp:9:38: warning: variable 'M' set but not used [-Wunused-but-set-variable]
     long double X[n], Y[n], s[n], d, M, D;
                                      ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 7 ms 376 KB Output is correct
8 Correct 8 ms 376 KB Output is correct
9 Correct 10 ms 376 KB Output is correct
10 Correct 11 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 6 ms 504 KB Output is correct
17 Correct 7 ms 376 KB Output is correct
18 Correct 9 ms 376 KB Output is correct
19 Correct 11 ms 376 KB Output is correct
20 Correct 11 ms 376 KB Output is correct