Submission #588572

# Submission time Handle Problem Language Result Execution time Memory
588572 2022-07-03T14:42:56 Z MohammadAghil Park (BOI16_park) C++17
100 / 100
319 ms 33604 KB
      #include <bits/stdc++.h>
//   #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
    using namespace std;
  typedef long long ll;
   typedef pair<int, int> pp;
    #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
      #define per(i,r,l) for(int i = (r); i >= (l); i--)
        #define rep(i,l,r) for(int i = (l); i < (r); i++)
           #define all(x) begin(x), end(x)
              #define sz(x) (int)(x).size()
                  #define pb push_back
                      #define ss second
                           #define ff first
                                   void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
     cin.tie(0) -> sync_with_stdio(0);
     // #ifndef ONLINE_JUDGE
     //      freopen("in.in", "r", stdin);
     //      freopen("out.out", "w", stdout);
     // #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 998244353, maxn = 5e3 + 5, lg = 22, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}

int par[maxn];
int get(int x){ return par[x] == -1? x: par[x] = get(par[x]); }
bool unite(int u, int v){
     u = get(u), v = get(v);
     if(u == v) return false;
     par[v] = u; return true;
}


int n, q;
ll h, w, x[maxn], y[maxn], r[maxn];
ll fre[4][4];

ll sq(ll a){
     ll s = max(0ll, ll(sqrt(a))-2);
     while((s+1)*(s+1) <= a) s++;
     return s;
}

ll dist(int a, int b){
     if(a > b) swap(a, b);
     if(b < n) return sq((x[a]-x[b])*(x[a]-x[b]) + (y[a]-y[b])*(y[a]-y[b])) - (r[a] + r[b]);
     if(b == n) return y[a] - r[a];
     if(b == n+1) return w - x[a] - r[a];
     if(b == n+2) return h - y[a] - r[a];
     return x[a] - r[a];
}

int main(){ IOS();
     cin >> n >> q >> w >> h;
     rep(i,0,n) cin >> x[i] >> y[i] >> r[i];
     vector<pair<ll, pp>> edge{{inf, {n, n}}};
     rep(i,0,n+4){
          par[i] = -1;
          rep(j,0,min(n,i)) edge.pb({dist(i, j), {i, j}});
     }
     sort(all(edge));
     rep(i,0,4) rep(j,0,4) fre[i][j] = -1;
     ll lst = edge[0].ff;
     for(auto[w, p]: edge){
          if(w - lst){
               rep(i,0,4) rep(j,0,4) if(fre[i][j] == -1 && get(n+i) == get(n+j)) fre[i][j] = lst;
          } lst = w;
          auto[u, v] = p;
          unite(u, v);
     }
     while(q--){
          ll r, p; cin >> r >> p; r <<= 1ll, p--;
          vector<int> ans{p};
          if(min({fre[(p+0)%4][(p+1)%4], fre[(p+0)%4][(p+2)%4], fre[(p+0)%4][(p+3)%4]}) >= r) ans.pb((p+1)%4);
          if(min({fre[(p+3)%4][(p+0)%4], fre[(p+3)%4][(p+1)%4], fre[(p+3)%4][(p+2)%4]}) >= r) ans.pb((p+3)%4);
          if(min({fre[(p+0)%4][(p+2)%4], fre[(p+0)%4][(p+3)%4], fre[(p+1)%4][(p+3)%4], fre[(p+1)%4][(p+2)%4]}) >= r) ans.pb((p+2)%4);
          sort(all(ans));
          for(int c: ans) cout << c+1; cout << '\n';
     }
     return 0;
}

Compilation message

park.cpp: In function 'int main()':
park.cpp:75:27: warning: narrowing conversion of 'p' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   75 |           vector<int> ans{p};
      |                           ^
park.cpp:75:27: warning: narrowing conversion of 'p' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
park.cpp:80:11: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   80 |           for(int c: ans) cout << c+1; cout << '\n';
      |           ^~~
park.cpp:80:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   80 |           for(int c: ans) cout << c+1; cout << '\n';
      |                                        ^~~~
# Verdict Execution time Memory Grader output
1 Correct 267 ms 33336 KB Output is correct
2 Correct 262 ms 33424 KB Output is correct
3 Correct 263 ms 33340 KB Output is correct
4 Correct 258 ms 33320 KB Output is correct
5 Correct 260 ms 33420 KB Output is correct
6 Correct 258 ms 33456 KB Output is correct
7 Correct 269 ms 33320 KB Output is correct
8 Correct 268 ms 33372 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 2188 KB Output is correct
2 Correct 39 ms 2140 KB Output is correct
3 Correct 37 ms 2136 KB Output is correct
4 Correct 37 ms 2100 KB Output is correct
5 Correct 38 ms 2136 KB Output is correct
6 Correct 43 ms 2192 KB Output is correct
7 Correct 31 ms 1748 KB Output is correct
8 Correct 32 ms 1740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 267 ms 33336 KB Output is correct
2 Correct 262 ms 33424 KB Output is correct
3 Correct 263 ms 33340 KB Output is correct
4 Correct 258 ms 33320 KB Output is correct
5 Correct 260 ms 33420 KB Output is correct
6 Correct 258 ms 33456 KB Output is correct
7 Correct 269 ms 33320 KB Output is correct
8 Correct 268 ms 33372 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 40 ms 2188 KB Output is correct
12 Correct 39 ms 2140 KB Output is correct
13 Correct 37 ms 2136 KB Output is correct
14 Correct 37 ms 2100 KB Output is correct
15 Correct 38 ms 2136 KB Output is correct
16 Correct 43 ms 2192 KB Output is correct
17 Correct 31 ms 1748 KB Output is correct
18 Correct 32 ms 1740 KB Output is correct
19 Correct 294 ms 33596 KB Output is correct
20 Correct 302 ms 33572 KB Output is correct
21 Correct 300 ms 33588 KB Output is correct
22 Correct 293 ms 33588 KB Output is correct
23 Correct 302 ms 33584 KB Output is correct
24 Correct 319 ms 33604 KB Output is correct