| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 293960 | Muhammetali | 통행료 (IOI18_highway) | C++11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "highway.h"
#include <bits/stdc++.h>
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define REP(i,a) for (int i = 0; i < (a); ++i)
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define trav(a,x) for (auto& a: x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
template<class T>bool tmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool tmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
ll san1,san2,res1,res2;
vl U,V;
vpl roads[1000],saher1,saher2,nodes[1000];
bool vis[1000];
void find()
{
sort(saher1.begin(),saher1.end());
sort(saher2.begin(),saher2.end());
ll k=0;
vi barla;
REP(i,sz(U))barla.pb(0);
ll g=ask(barla);
REP(i,sz(saher1))
{
if (k!=saher1[i].f)
{
k++;
if (g!=ask(barla))
{
k--;
g=ask(barla);
for (ll j=i-1;j>=0;j--)
{
barla[saher1[i].s]=0;
if (g!=ask(barla))
{
res1=saher1[i].f;
break;
}
}
break;
}
}
barla[saher1[i].s]=1;
}
REP(i,sz(saher2))
{
if (k!=saher2[i].f)
{
k++;
if (g!=ask(barla))
{
k--;
g=ask(barla);
for (ll j=i-1;j>=0;j--)
{
barla[saher2[i].s]=0;
if (g!=ask(barla))
{
res2=saher2[i].f;
break;
}
}
break;
}
}
barla[saher1[i].s]=1;
}
}
void bfs()
{
bool b=0;
REP(i,sz(saher1))
{
REP(j,sz(roads[saher1[i].s]))
{
if (!vis[nodes[saher1[i].s][j].f])
{
vis[nodes[saher1[i].s][j].f]=1;
saher1.pb({san1,nodes[saher1[i].s][j].s});
}
}
}
san1++;
REP(i,sz(saher2))
{
REP(j,sz(nodes[saher2[i].s]))
{
if (!vis[nodes[saher2[i].s][j].f])
{
vis[nodes[saher2[i].s][j].f]=1;
saher2.pb({san2,nodes[saher2[i].s][j].s});
}
}
}
san2++;
if (b)bfs();
else find();
}
void binary_search()
{
ll k=sz(U); k/=2;
vi barla;
REP(i,sz(U))barla.pb(0);
ll h=ask(barla);
barla[k]=1;
while(h==ask(barla))
{
barla[k]=0;
k/=2;
barla[k]=1;
}
vis[roads[k].f]=1;
vis[roads[k].s]=1;
saher1.pb({0,roads[k].f});
saher2.pb({0,roads[k].s});
bfs();
}
void find_pair(ll N, vector<ll> U, vector<ll> V, ll A, ll B)
{
REP(i,sz(U))
{
roads[i].pb({U[i],V[i]});
nodes[U[i]].pb({V[i],i});
nodes[V[i]].pb({U[i],i});
}
binary_search();
answer(res1,res2);
}
