Submission #331727

# Submission time Handle Problem Language Result Execution time Memory
331727 2020-11-29T19:01:28 Z Sho10 Santa Claus (RMI19_santa) C++14
30 / 100
1000 ms 5612 KB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll t,n,ans[100005];
struct house{
    ll pos,h,val;
};
house a[100005];
ll check(ll l,ll r){
for(ll i=r+1;i<=n;i++)
{
    if(a[i].h==0){
        return 0;
    }
}
multiset<ll>s;
for(ll i=1;i<=r;i++)
{
    if(a[i].h==0){
        s.insert(a[i].val);
    }else {
    if(i<l){
        auto it=s.lower_bound(a[i].val);
        if(it!=s.end()){
            s.erase(it);
        }
    }
}
}
for(ll i=r;i>=l;i--)
{
    if(a[i].h==1){
        auto it=s.lower_bound(a[i].val);
        if(it!=s.end()){
            s.erase(it);
        }
    }
}
return 1-(s.size()!=0);
}
int32_t main(){
CODE_START;
cin>>t;
while(t--){
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i].pos;
    }
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i].h;
    }
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i].val;
    }
  ll last=0;
  for(ll i=1;i<=n;i++)
  {
      while(last<i&&check(last+1,i)){
        last++;
      }
      if(last==0){
        cout<<"-1"<<' ';
      }else {
      cout<<2*a[i].pos-a[last].pos<<' ';
      }

  }
  cout<<endl;
}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 6 ms 364 KB Output is correct
3 Correct 562 ms 876 KB Output is correct
4 Execution timed out 1066 ms 1132 KB Time limit exceeded
5 Execution timed out 1081 ms 876 KB Time limit exceeded
6 Execution timed out 1085 ms 1260 KB Time limit exceeded
7 Execution timed out 1085 ms 1900 KB Time limit exceeded
8 Execution timed out 1085 ms 2668 KB Time limit exceeded
9 Execution timed out 1080 ms 5484 KB Time limit exceeded
10 Execution timed out 1094 ms 5612 KB Time limit exceeded