답안 #275959

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
275959 2020-08-20T08:38:21 Z 최은수(#5098) Circus (Balkan15_CIRCUS) C++17
100 / 100
984 ms 22472 KB
#include"circus.h"
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
static int n,m;
static vector<int>p;
static int cal[100010];
static int mn[100010];
vector<pi>pmn,pmx;
void init(int N,int M,int P[])
{
    n=N,m=M;
    for(int i=0;i<n;i++)
        p.eb(P[i]);
    sort(all(p));
    p.erase(unique(all(p)),p.end());
    n=p.size();
    for(int i=0;i<n;i++)
        cal[i]=m-p[i];
    for(int i=0;i<30;i++)
    {
        for(int j=0;j<n;j++)
            mn[j]=inf;
        for(int j=0;j<n;j++)
        {
            if(j!=0)
                mn[j]=min(mn[j],mn[j-1]);
            cal[j]=min(cal[j],mn[j]+p[j]);
            int pos=lower_bound(all(p),p[j]+cal[j])-p.begin();
            if(pos!=n)
                mn[pos]=-p[j];
        }
        for(int j=0;j<n;j++)
            mn[j]=inf;
        for(int j=n;j-->0;)
        {
            if(j!=n-1)
                mn[j]=min(mn[j],mn[j+1]);
            cal[j]=min(cal[j],mn[j]-p[j]);
            int pos=upper_bound(all(p),p[j]-cal[j])-p.begin()-1;
            if(pos!=-1)
                mn[pos]=p[j];
        }
    }
    vector<pi>p1,p2;
    for(int i=0;i<n;i++)
    {
        p1.eb(p[i]+cal[i],-p[i]);
        p2.eb(p[i]-cal[i],p[i]);
    }
    sort(all(p1));
    sort(all(p2),[](const pi&x,const pi&y){return x.fi==y.fi?x.se<y.se:x.fi>y.fi;});
    int pr=inf;
    for(pi&t:p1)
        if(t.se<pr)
            pmx.eb(t),pr=t.se;
    pr=inf;
    for(pi&t:p2)
        if(t.se<pr)
            pmn.eb(t),pr=t.se;
    reverse(all(pmn));
    p.eb(m);
    return;
}
int minLength(int D)
{
    int d=D;
    int ans=m-d;
    {
        int p=upper_bound(all(pmx),pi(d,inf))-pmx.begin()-1;
        if(p!=-1)
            ans=min(ans,d+pmx[p].se);
    }
    {
        int p=lower_bound(all(pmn),pi(d,-inf))-pmn.begin();
        if(p!=(int)pmn.size())
            ans=min(ans,pmn[p].se-d);
    }
    return ans;
}

Compilation message

grader.cpp: In function 'int main()':
grader.cpp:14:12: warning: unused variable 'max_code' [-Wunused-variable]
   14 |  long long max_code;
      |            ^~~~~~~~
grader.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |  scanf("%d%d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~
grader.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |   scanf("%d", &P[i]);
      |   ~~~~~^~~~~~~~~~~~~
grader.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
grader.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |   scanf("%d", &d);
      |   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 355 ms 5612 KB Output is correct
2 Correct 341 ms 5608 KB Output is correct
3 Correct 361 ms 5612 KB Output is correct
4 Correct 365 ms 5612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
6 Correct 8 ms 384 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 416 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
6 Correct 8 ms 384 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 6 ms 512 KB Output is correct
9 Correct 473 ms 8648 KB Output is correct
10 Correct 420 ms 4988 KB Output is correct
11 Correct 451 ms 4488 KB Output is correct
12 Correct 496 ms 9080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 355 ms 5612 KB Output is correct
2 Correct 341 ms 5608 KB Output is correct
3 Correct 361 ms 5612 KB Output is correct
4 Correct 365 ms 5612 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 416 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 8 ms 384 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 335 ms 6636 KB Output is correct
14 Correct 339 ms 6508 KB Output is correct
15 Correct 333 ms 6256 KB Output is correct
16 Correct 332 ms 6384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 355 ms 5612 KB Output is correct
2 Correct 341 ms 5608 KB Output is correct
3 Correct 361 ms 5612 KB Output is correct
4 Correct 365 ms 5612 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 416 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 8 ms 384 KB Output is correct
10 Correct 8 ms 384 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 473 ms 8648 KB Output is correct
14 Correct 420 ms 4988 KB Output is correct
15 Correct 451 ms 4488 KB Output is correct
16 Correct 496 ms 9080 KB Output is correct
17 Correct 335 ms 6636 KB Output is correct
18 Correct 339 ms 6508 KB Output is correct
19 Correct 333 ms 6256 KB Output is correct
20 Correct 332 ms 6384 KB Output is correct
21 Correct 984 ms 16876 KB Output is correct
22 Correct 951 ms 17004 KB Output is correct
23 Correct 983 ms 20168 KB Output is correct
24 Correct 978 ms 22472 KB Output is correct