# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
905056 |
2024-01-12T13:32:29 Z |
browntoad |
Park (BOI16_park) |
C++14 |
|
628 ms |
54524 KB |
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define RREP1(i,n) for (int i=(n); i>=1; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define pip pair<int, pii>
#define ppi pair<pii, int>
#define pdd pair<double ,double>
#define pcc pair<char, char>
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
const ll inf = 1ll<<60;
const int iinf=2147483647;
const ll mod = 1e9+7;
const ll maxn=2005;
const ll maxm=1e5+5;
const double PI=acos(-1);
ll pw(ll x, ll p, ll m=mod){
if (p < 0) return 0;
ll ret=1;
while (p>0){
if (p&1){
ret*=x;
ret%=m;
}
x*=x;
x%=m;
p>>=1;
}
return ret;
}
ll inv(ll a, ll m=mod){
return pw(a,m-2,m);
}
vector<bool> ex(16);
struct Point{
int x, y;
};
int dis2(Point a, Point b){
return SQ(a.x-b.x)+SQ(a.y-b.y);
}
struct Circ{
Point a;
int r, typ, id;
};
bool cmpc(Circ a, Circ b){
return a.r<b.r;
}
struct Pair{
int a, b;
int r; // when it will overlap
};
bool cmpp(Pair a, Pair b){
return a.r<b.r;
}
struct Quer{
int r;
int pos, id;
};
bool cmpq(Quer a, Quer b){
return a.r<b.r;
}
vector<int> par(maxn), msk(maxn);
int fin(int a){
if (a == par[a]) return a;
return par[a] = fin(par[a]);
}
void merg(int a, int b){
a = fin(a); b = fin(b);
par[a] = b;
msk[b] |= msk[a];
ex[msk[b]] = 1;
}
int n, q, mx, my;
vector<Circ> vc, tmp;
vector<Pair> pr;
vector<Quer> quer;
vector<string> ans(maxm);
bool ex2(int a, int b){
if (a == 1 && b == 3){
REP(i, 16){
if (ex[i] && __builtin_popcount(i) >= 2 && (i != 9 && i != 6)) return 0;
}
}
else {
REP(i, 16){
if (ex[i] && __builtin_popcount(i) >= 2 && (i != 12 && i != 3)) return 0;
}
}
return 1;
}
bool ex1(int a, int b){
// a < b; a and b share an edge
if (b-a == 2) return ex2(a, b);
int typ;
if (a == 1 && b == 2) typ = 2;
if (a == 2 && b == 3) typ = 1;
if (a == 3 && b == 4) typ = 0;
if (a == 1 && b == 4) typ = 3;
REP(i, 16){
if (!ex[i]) continue;
if (i&(1<<typ)){
if (i != (1<<typ)) return 0;
}
}
return 1;
}
signed main(){
IOS();
cin>>n>>q>>mx>>my;
REP(i, n){
par[i] = i;
}
tmp = vector<Circ> (n);
REP(i, n){
cin>>tmp[i].a.x>>tmp[i].a.y>>tmp[i].r;
tmp[i].id = i;
}
REP(i, n){
vc.pb({tmp[i].a, my-tmp[i].a.y-tmp[i].r+1, 1, tmp[i].id});
vc.pb({tmp[i].a, mx-tmp[i].a.x-tmp[i].r+1, 2, tmp[i].id});
vc.pb({tmp[i].a, tmp[i].a.y-tmp[i].r+1, 4, tmp[i].id});
vc.pb({tmp[i].a, tmp[i].a.x-tmp[i].r+1, 8, tmp[i].id});
}
REP(i, n){
FOR(j, i+1, n){
int tt = dis2(tmp[i].a, tmp[j].a);
int l = 1, r = 1000000000,mid;
while(l < r){
mid = (l+r)>>1;
if (tmp[i].r+tmp[j].r+2*mid > 2000000000 || SQ(tmp[i].r+tmp[j].r+2*mid) > tt){
r = mid;
}
else {
l = mid+1;
}
}
pr.pb({i, j, l});
}
}
quer = vector<Quer> (q);
REP(i, q){
cin>>quer[i].r>>quer[i].pos;
quer[i].id = i;
}
sort(ALL(vc), cmpc); sort(ALL(pr), cmpp); sort(ALL(quer), cmpq);
int pa = 0, pb = 0;
REP(i, q){
while(pa < SZ(vc) && vc[pa].r <= quer[i].r){
msk[fin(vc[pa].id)] |= vc[pa].typ;
ex[msk[fin(vc[pa].id)]] = 1;
pa++;
}
while(pb < SZ(pr) && pr[pb].r <= quer[i].r){
merg(pr[pb].a, pr[pb].b);
pb++;
}
string ou;
REP1(j, quer[i].pos-1){
if (ex1(j, quer[i].pos)) ou += (char)(j+'0');
}
ou += (char)(quer[i].pos + '0');
FOR(j, quer[i].pos+1, 5){
if (ex1(quer[i].pos, j)) ou += (char)(j+'0');
}
ans[quer[i].id] = ou;
}
REP(i, q) cout<<ans[i]<<endl;
}
/*
5 3
16 11
11 8 1
6 10 1
7 3 2
10 4 1
15 5 1
1 1
2 2
2 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
628 ms |
53260 KB |
Output is correct |
2 |
Correct |
628 ms |
53644 KB |
Output is correct |
3 |
Incorrect |
627 ms |
54524 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
58 ms |
6912 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
628 ms |
53260 KB |
Output is correct |
2 |
Correct |
628 ms |
53644 KB |
Output is correct |
3 |
Incorrect |
627 ms |
54524 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |