Submission #1213404

#TimeUsernameProblemLanguageResultExecution timeMemory
1213404sasdeCountries (BOI06_countries)C++20
100 / 100
16 ms23880 KiB
#include<bits/stdc++.h>
using namespace std;
bool M1;
#define task "aws"
#define all(x) x.begin(),x.end()
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii,ii>
#define se second
#define fi first
#define ffi fi.fi
#define sfi se.fi
#define sse se.se
#define fse fi.se
#define lt(i, c, d) for(int i = c; i <= d; ++i)
#define fl(i, c, d) for(int i = d; i >= c; --i)
#define pb push_back
#define emb emplace_back
#define emf emplace_front
#define em emplace
#define look_memory cerr<<abs(&M2-&M1)/1024.0/1024<<'\n'
#define look_time   cerr << "TIME : " << clock() * 0.001 << "s" <<'\n'
const int N=1e6+5,lg=30,mod=1e9+7;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int u,int v){
 return u+rd()%(v-u+1);
}
#define int long long
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,-1,0,1,1,-1,1,-1};
struct pt{
    int first,second,w;
}a[N];
int dist(pt x,pt y){
    return (x.fi-y.fi)*(x.fi-y.fi)+(x.se-y.se)*(x.se-y.se);
}
int node,ans[N];
vector<int>edge[N];
bool ok[N];
void dfs(int u){
    ok[u]=true;
    for(int v:edge[u]){
        ans[v]=ans[u];
        dfs(v);
    }
}
bool M2;
void solve(){
    cin >> node;
    for(int i=1;i<=node;++i)cin >> a[i].fi >> a[i].se >> a[i].w;
    for(int i=1;i<=node;++i){
        bool ok=false;
        int qq=-1e18,lastd=1e9,last=0,vt=0;
        for(int j=1;j<=node;++j){
            if(i==j)continue;
            int d=dist(a[i],a[j]);
            // if(i==2)cout <<a[j].w*lastd<<" "<<last*d<<'\n';
            if(qq<a[j].w-a[i].w*d){
                qq=a[j].w-a[i].w*d;
            }
            if(a[j].w*lastd>last*d){
                last=a[j].w;
                lastd=d;ok=false;vt=j;
            }
            else if(lastd*a[j].w==last*d){
                ok=true;
            }

        }
        if(qq<=0)ans[i]=-2;
        else if(ok)ans[i]=-1;
        else{
            edge[vt].emb(i);
        }
    }
    for(int i=1;i<=node;++i){
        if(ans[i]!=0&&!ok[i]){
            int tmp=ans[i];
            ans[i]=i;
            dfs(i);
            ans[i]=tmp;
        }
    }
    for(int i=1;i<=node;++i){
        if(ans[i]==-2)cout <<"K";
        else if(ans[i]==-1)cout<<"D";
        else cout <<ans[i];
        cout <<'\n';
    }
}
main()
{
  srand(time(0));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    if(fopen(task".inp","r")){
      freopen(task".inp","r",stdin);
      freopen(task".out","w",stdout);
    }
    int t=1;
 //   cin >> t;
while(t--){
    solve();
}
look_memory;
look_time;
}

Compilation message (stderr)

countries.cpp:91:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   91 | main()
      | ^~~~
countries.cpp: In function 'int main()':
countries.cpp:98:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |       freopen(task".inp","r",stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
countries.cpp:99:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |       freopen(task".out","w",stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...