Submission #575535

# Submission time Handle Problem Language Result Execution time Memory
575535 2022-06-10T21:07:10 Z FatihSolak Ideal city (IOI12_city) C++17
0 / 100
1000 ms 5844 KB
#include <bits/stdc++.h>
#define N 100005
using namespace std;
const int mod = 1e9;
long long ans = 0;
int group[N];
vector<int> adj[N];
int sz[N];
int sub[N];
vector<int> v[N];
int n;
void dfs(int v,int par){
    sub[v] = sz[v];
    for(auto u:adj[v]){
        if(u == par)continue;
        dfs(u,v);
        sub[v] += sub[u];
        ans += (long long)sub[u]*(n-sub[u]);
    }
}
void solve(){
    int cnt = 1;
    int bef = 1;
    for(int i = 0;i<n;i++){
        int tmp = cnt;
        sort(v[i].begin(),v[i].end());
        for(int j = 0;j<v[i].size();j++){
            sz[cnt] = 0;
            int r = j-1;
            bool last = 0;
            while(r  + 1< v[i].size() && v[i][j] + (r-j+1) == v[i][r+1]){
                r++;
                if(last == 0 && bef <= group[v[i][r]]){
                    adj[group[v[i][r]]].push_back(cnt);
                    adj[cnt].push_back(group[v[i][r]]);
                    last = 1;
                }
                else last = 0;
                sz[cnt]++;
                group[v[i][r]] = cnt;
            }
            j = r;
            cnt++;
        }
        bef = tmp;
    }
    dfs(1,0);
}
int DistanceSum(int n_, int *x, int *y) {
    n = n_;
    vector<int> compressx,compressy;
    for(int i = 0;i<n;i++){
        compressx.push_back(x[i]);
        compressy.push_back(y[i]);
    }
    sort(compressx.begin(),compressx.end());
    sort(compressy.begin(),compressy.end());
    compressx.resize(unique(compressx.begin(),compressx.end())-compressx.begin());
    compressy.resize(unique(compressy.begin(),compressy.end())-compressy.begin());
    for(int i = 0;i<n;i++){
        x[i] = lower_bound(compressx.begin(),compressx.end(),x[i]) - compressx.begin();
        y[i] = lower_bound(compressy.begin(),compressy.end(),y[i]) - compressy.begin();
    }
    for(int i = 0;i<n;i++){
        v[x[i]].push_back(y[i]);
    }
    solve();
    for(int i = 0;i<n;i++){
        v[i].clear();
        adj[i].clear();
        group[i] = 0;
    }
    for(int i = 0;i<n;i++){
        v[y[i]].push_back(x[i]);
    }
    solve();
    return ans%mod;
}

Compilation message

city.cpp: In function 'void solve()':
city.cpp:27:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for(int j = 0;j<v[i].size();j++){
      |                       ~^~~~~~~~~~~~
city.cpp:31:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |             while(r  + 1< v[i].size() && v[i][j] + (r-j+1) == v[i][r+1]){
      |                   ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Incorrect 2 ms 4948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 5040 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 5588 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 5844 KB Time limit exceeded
2 Halted 0 ms 0 KB -