Submission #61807

#TimeUsernameProblemLanguageResultExecution timeMemory
61807zetapiIdeal city (IOI12_city)C++14
23 / 100
406 ms69540 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define ll long long #define itr ::iterator typedef pair<ll,ll> pii; const ll MAX=1e6; const ll mod=1e9; vector<pii> vec; set<ll> adj[MAX]; ll res,value[MAX],sum[MAX],dp[MAX]; void dfs(int node,int par) { //cout<<node<<" "<<value[node]<<" dfs \n"; for(auto A:adj[node]) { if(A==par) continue; dfs(A,node); sum[node]+=sum[A]; sum[node]%=mod; dp[node]+=dp[A]; dp[node]%=mod; } //cout<<"sum "<<node<<" "<<sum[node]<<"\n"; dp[node]+=sum[node]; dp[node]%=mod; sum[node]+=value[node]; sum[node]%=mod; res+=(dp[node]*value[node])%mod; res%=mod; return ; } void cal(int N,int *X,int *Y) { for(int A=1;A<=N;A++) { dp[A]=0; sum[A]=0; value[A]=0; adj[A].clear(); } int ptr=0; vector<pii> vec; map<pii,int> mark; for(int A=0;A<N;A++) vec.pb(mp(X[A],Y[A])); vec.pb(mp(0,0)); sort(vec.begin(),vec.end()); for(int A=1;A<vec.size();A++) { if(vec[A].first==vec[A-1].first and vec[A].second==vec[A-1].second+1) { value[ptr]++; mark[mp(vec[A].first,vec[A].second)]=ptr; } else { value[++ptr]++; mark[mp(vec[A].first,vec[A].second)]=ptr; } //cout<<vec[A].first<<" "<<vec[A].second<<" "<<mark[vec[A]]<<"\n"; } for(int A=1;A<vec.size();A++) { if(mark[mp(vec[A].first-1,vec[A].second)]) { adj[mark[vec[A]]].insert(mark[mp(vec[A].first-1,vec[A].second)]); adj[mark[mp(vec[A].first-1,vec[A].second)]].insert(mark[vec[A]]); //cout<<mark[vec[A]]<<" "<<mark[mp(vec[A].first-1,vec[A].second)]<<"\n"; } } dfs(1,0); return ; } int DistanceSum(int N, int *X, int *Y) { cal(N,X,Y); for(int A=0;A<N;A++) swap(X[A],Y[A]); cal(N,X,Y); return res; } /*signed main() { ios_base::sync_with_stdio(false); int X[]={1,1,2,2}; int Y[]={1,2,1,2}; cout<<DistanceSum(4,X,Y); return 0; }*/

Compilation message (stderr)

city.cpp: In function 'void cal(int, int*, int*)':
city.cpp:59:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int A=1;A<vec.size();A++)
              ~^~~~~~~~~~~
city.cpp:73:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int A=1;A<vec.size();A++)
              ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...