Submission #939115

# Submission time Handle Problem Language Result Execution time Memory
939115 2024-03-06T05:50:37 Z winter0101 City Mapping (NOI18_citymapping) C++14
32 / 100
12 ms 8612 KB
#include<bits/stdc++.h>
#include "citymapping.h"
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
vector<pii>aaa[1009];
mt19937_64 rng(10101994);
long long d[1009][1009];
long long ask(int x,int y){
if (d[x][y]!=-1)return d[x][y];
return d[x][y]=d[y][x]=get_distance(x,y);
}
bool add[1009];
vector<int>xd[1009];
void solve(vector<int>&tmp){
shuffle(all(tmp),rng);
for (auto v:tmp)add[v]=0;
if (sz(tmp)<=1)return;
int s=tmp[0],t=tmp.back();
ask(s,t);
vector<int>vertice;
for (auto v:tmp){
if (ask(s,v)+ask(t,v)==ask(s,t)){
vertice.pb(v);
add[v]=1;
}
}
sort(all(vertice),[&](int i,int j){
return ask(s,i)<ask(s,j);
});
auto add_edg=[&](int u,int v,int w){
aaa[u].pb({v,w});
aaa[v].pb({u,w});
cerr<<u<<" "<<v<<" "<<w<<'\n';
return;
};
for1(i,1,sz(vertice)-1){
add_edg(vertice[i],vertice[i-1],ask(vertice[i],s)-ask(vertice[i-1],s));
}
for(auto v:tmp){
if (add[v])continue;
for (auto u:vertice){
if (ask(s,v)-ask(s,u)==ask(t,v)-ask(t,u)&&ask(s,v)>ask(s,u)){
xd[u].pb(v);
}
}
}
for (auto u:vertice){
if (!xd[u].empty()){
vector<int>cop;
cop.swap(xd[u]);
int mn=cop[0];
for (auto v:cop){
if (ask(s,v)<ask(s,mn)){
mn=v;
}
}
add_edg(u,mn,ask(s,mn)-ask(s,u));
solve(cop);
}
}
}
void find_roads(int N, int Q, int A[], int B[], int W[]) {
	for1(i,1,N){
	for1(j,1,N){
	d[i][j]=-1;
	}
	d[i][i]=0;
	}
	vector<int>tree;
	for1(i,1,N)tree.pb(i);
	solve(tree);
	int cnt=0;
	for1(i,1,N){
	for (auto v:aaa[i]){
    if (v.fi>i){
    A[cnt]=v.fi,B[cnt]=i,W[cnt]=v.se;
    cnt++;
    }
	}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8540 KB Correct: 5710 out of 500000 queries used.
2 Incorrect 10 ms 8536 KB Reported list of edges differ from actual.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8540 KB Correct: 5710 out of 500000 queries used.
2 Incorrect 10 ms 8536 KB Reported list of edges differ from actual.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8536 KB Correct: 4788 out of 12000 queries used.
2 Correct 10 ms 8536 KB Correct: 5069 out of 12000 queries used.
3 Correct 10 ms 8612 KB Correct: 3929 out of 12000 queries used.
4 Correct 10 ms 8564 KB Correct: 3862 out of 12000 queries used.
5 Correct 10 ms 8548 KB Correct: 3560 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 12 ms 8536 KB Correct: 4788 out of 12000 queries used.
2 Correct 10 ms 8536 KB Correct: 5069 out of 12000 queries used.
3 Correct 10 ms 8612 KB Correct: 3929 out of 12000 queries used.
4 Correct 10 ms 8564 KB Correct: 3862 out of 12000 queries used.
5 Correct 10 ms 8548 KB Correct: 3560 out of 12000 queries used.
6 Correct 10 ms 8576 KB Correct: 4798 out of 12000 queries used.
7 Correct 12 ms 8552 KB Correct: 8654 out of 12000 queries used.
8 Correct 11 ms 8540 KB Correct: 5137 out of 12000 queries used.
9 Correct 10 ms 8540 KB Correct: 6502 out of 12000 queries used.
10 Correct 11 ms 8540 KB Correct: 3416 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8540 KB Correct: 5710 out of 500000 queries used.
2 Incorrect 10 ms 8536 KB Reported list of edges differ from actual.
3 Halted 0 ms 0 KB -