/*
________ ___ ________ ________ ________ ___ ________ ________ ________
|\ ____\|\ \|\ ____\|\ __ \ |\ ___ \|\ \|\ ____\|\ ____\|\ __ \
\ \ \___|\ \ \ \ \___|\ \ \|\ \ \ \ \\ \ \ \ \ \ \___|\ \ \___|\ \ \|\ \
\ \ \ __\ \ \ \ \ __\ \ __ \ \ \ \\ \ \ \ \ \ \ __\ \ \ __\ \ __ \
\ \ \|\ \ \ \ \ \|\ \ \ \ \ \ \ \ \\ \ \ \ \ \ \|\ \ \ \|\ \ \ \ \ \
\ \_______\ \__\ \_______\ \__\ \__\ \ \__\\ \__\ \__\ \_______\ \_______\ \__\ \__\
\|_______|\|__|\|_______|\|__|\|__| \|__| \|__|\|__|\|_______|\|_______|\|__|\|__|
________ ________ ________ ________ ___ ___ ________ _________ ___ ________ ________
|\ __ \|\ __ \|\ __ \|\ ___ \|\ \|\ \|\ ____\\___ ___\\ \|\ __ \|\ ___ \
\ \ \|\ \ \ \|\ \ \ \|\ \ \ \_|\ \ \ \\\ \ \ \___\|___ \ \_\ \ \ \ \|\ \ \ \\ \ \
\ \ ____\ \ _ _\ \ \\\ \ \ \ \\ \ \ \\\ \ \ \ \ \ \ \ \ \ \ \\\ \ \ \\ \ \
\ \ \___|\ \ \\ \\ \ \\\ \ \ \_\\ \ \ \\\ \ \ \____ \ \ \ \ \ \ \ \\\ \ \ \\ \ \
\ \__\ \ \__\\ _\\ \_______\ \_______\ \_______\ \_______\ \ \__\ \ \__\ \_______\ \__\\ \__\
\|__| \|__|\|__|\|_______|\|_______|\|_______|\|_______| \|__| \|__|\|_______|\|__| \|__|
Written by: giga nigga
*/
// #include "largest.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ull mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
// mt19937_64 rng(1);
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
double wow = (double) ((ull) rng()) / ((ull)(0-1));
return wow * (r - l) + l;
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
#include "rail.h"
void findLocation(int n, int first, int location[], int stype[]);
namespace InteractorLib{
const int N = 50;
int graph[N][N];
int o_cnt = 0;
double grade(){
int n; cin >> n;
vector<int> pos(n), type(n);
for(int i = 0; i < n; ++i) cin >> pos[i] >> type[i];
memset(graph, 63, sizeof graph);
for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j){
if (i == j) graph[i][j] = 0;
else{
if (pos[i] < pos[j] && type[i] == 1 && type[j] == 2){
graph[i][j] = pos[j] - pos[i];
}
if (pos[i] > pos[j] && type[i] == 2 && type[j] == 1) {
graph[i][j] = pos[i] - pos[j];
}
}
}
for(int k = 0; k < n; ++k) for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j)
minimize(graph[i][j], graph[i][k] + graph[k][j]);
int location[n], stype[n];
findLocation(n, pos[0], location, stype);
cout << "Output: \n";
for(int i = 0; i < n; ++i) cout << location[i] << " " << stype[i] << "\n";
for(int i = 0; i < n; ++i){
if (location[i] != pos[i] || stype[i] != type[i]){
return 0;
}
}
return (double) (3*n-3) / max(3*n-3, o_cnt);
}
int getDistance(int i, int j){
o_cnt++;
cout << "? " << i << " " << j << endl;
// int ans; cin >> ans;
int ans = graph[i][j];
cout << "! " << ans << "\n";
return ans;
}
}
void findLocation(int n, int first, int location[], int stype[]){
location[0] = first; stype[0] = 1;
vector<int> dis0(n);
for(int i = 1; i < n; ++i) dis0[i] = getDistance(0, i);
vector<pair<int, int>> stations;
for(int i = 1; i < n; ++i) stations.push_back(make_pair(dis0[i], i));
sort(ALL(stations));
int i1 = stations[0].second;
location[i1] = location[0] + dis0[i1];
stype[i1] = 2;
vector<int> dis1(n);
for(int i = 1; i < n; ++i) if (i != i1){
dis1[i] = getDistance(i1, i);
}
vector<int> right_part, left_part;
for(int i = 1; i < n-1; ++i){
int j = stations[i].second;
if (dis0[i1] + dis1[j] == dis0[j]){
left_part.push_back(j);
}
else{
right_part.push_back(j);
}
}
map<int, int> mp;
// expand to the right
int ma = -1;
vector<int> S;
for(int i: right_part){
if (ma == -1){
ma = i;
stype[i] = 2;
location[i] = dis0[i] + location[0];
S.push_back(location[i]);
mp[location[i]] = i;
continue;
}
cout << "Clihh\n";
int dih = getDistance(ma, i);
if (dis0[ma] + dih == dis0[i]){
stype[i] = 1;
location[i] = location[ma] - dih;
}
else{
int cur = *lower_bound(ALL(S), location[ma] - dih);
cur = mp[cur];
if (dis0[cur] + getDistance(cur, i) == dis0[i]){
stype[i] = 1;
location[i] = location[ma] - dih;
}
else{
stype[i] = 2;
location[i] = location[0] + dis0[i];
}
}
}
// expand to the left
S.clear();
int mi = -1;
for(int i: left_part){
if (dis1[i] < dis0[i1]){
stype[i] = 1;
location[i] = location[i1] - dis1[i];
continue;
}
if (mi == -1){
mi = i;
stype[i] = 1;
location[i] = location[i1] - dis1[i];
S.push_back(location[i]);
mp[location[i]] = i;
continue;
}
int dih = getDistance(mi, i);
if (dis0[mi] + dih == dis0[i]){
stype[i] = 2;
location[i] = location[mi] + dih;
}
else{
int cur = *lower_bound(ALL(S), location[mi] + dih, greater<int>());
cur = mp[cur];
if (dis1[cur] + getDistance(cur, i) == dis1[i]){
stype[i] = 2;
location[i] = location[mi] + dih;
}
else{
mi = i;
stype[i] = 1;
location[i] = location[i1] - dis1[i];
S.push_back(location[i]);
mp[location[i]] = i;
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |