Submission #226603

# Submission time Handle Problem Language Result Execution time Memory
226603 2020-04-24T13:25:39 Z MKopchev Countries (BOI06_countries) C++14
100 / 100
7 ms 512 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e3+42;

struct city
{
    int x,y,strength;
};
city inp[nmax];
int n;

int dist(city a,city b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int score(city i,city best,city current)
{
    pair<int,int> u={best.strength,dist(i,best)};
    pair<int,int> v={current.strength,dist(i,current)};

    if(i.strength*v.second>=v.first)return -1;

    if(u.first*v.second<u.second*v.first)return 1;
    if(u.first*v.second==u.second*v.first)return 0;
    return -1;
}

int parent[nmax];
int main()
{
    scanf("%i",&n);

    for(int i=1;i<=n;i++)
        scanf("%i%i%i",&inp[i].x,&inp[i].y,&inp[i].strength);

    inp[0].strength=-1;

    for(int i=1;i<=n;i++)
    {
        int best=0,cnt=1;

        for(int j=1;j<=n;j++)
            if(j!=i)
            {
                int type=score(inp[i],inp[best],inp[j]);

                if(type==1)best=j,cnt=1;
                else if(type==0)cnt++;
            }

        if(best==0)parent[i]=-1;
        else if(cnt==1)parent[i]=best;
        else parent[i]=0;
    }

    for(int i=1;i<=n;i++)
    {
        int best=parent[i];
        if(parent[i]>0)
        {
            while(parent[best]>0)best=parent[best];
        }
        if(parent[i]==-1)printf("K\n");
        else if(parent[i])printf("%i\n",best);
        else printf("D\n");
    }
    return 0;
}

Compilation message

countries.cpp: In function 'int main()':
countries.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&n);
     ~~~~~^~~~~~~~~
countries.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i%i%i",&inp[i].x,&inp[i].y,&inp[i].strength);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 6 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 7 ms 384 KB Output is correct
19 Correct 7 ms 384 KB Output is correct
20 Correct 7 ms 384 KB Output is correct