답안 #477380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477380 2021-10-01T21:25:59 Z leaked Safety (NOI18_safety) C++14
71 / 100
250 ms 25240 KB
#include <bits/stdc++.h>


#define m_p make_pair
#define pw2(x) (1LL<<x)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define f first
#define sz(x) (int)x.size()
#define len(x) (int)x.size()
#define pb push_back
#define s second
#define vec vector
#define REP(i, a,b) for(int i=(a);i<(b);i++)
#define REPD(i, a,b) for(int i=(a);i>=(b);--i)
#define file "name"
#define fi first
#define se second
using namespace std;
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
typedef pair<long long, long long> pll;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
void INPUT(bool F=0){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    if(F){
        freopen(file".in","r",stdin);
        freopen(file".out","w",stdout);
    }
}

struct myset{
    multiset<ll> st;
    ll ta=0;
    void add(ll x){
        x-=ta;
        st.insert(x);
    }
    ll gb(){
        assert(sz(st));
        return *st.rbegin()+ta;
    }
    ll gf(){
        assert(sz(st));
        return *st.begin()+ta;
    }
};
signed main(){
    INPUT();
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    myset l,r;
    int n,t;
    cin>>n>>t;
    ll ans=1e18;
    ll k=0,b=0;
    auto insrt=[&](ll x){
        l.add(x);l.add(x);k++;b-=x;
        while(sz(l.st)!=sz(r.st)){
            ll y=l.gb();l.st.erase(--l.st.end());
            r.add(y);
        }
    };
    auto fix=[&](){
        while(r.gf()<l.gb()){
            ll x=l.gb();ll y=r.gf();
            l.st.erase(--l.st.end());r.st.erase(r.st.begin());
            l.add(y);r.add(x);
        }
    };
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        l.ta-=t;r.ta+=t;b-=1ll*sz(r.st)*t;
        insrt(x);fix();
//        for(auto &q : l.st) debug()<<imie(q+l.ta);
//        for(auto &q : r.st) debug()<<imie(q+r.ta);
//        cout<<endl;
//        debug()<<imie(k);
    }
//    debug()<<imie(b)imie(k);
    vec<ll>xs;
    while(sz(l.st)) xs.pb(l.gf()),l.st.erase(l.st.begin());
    while(sz(r.st)) xs.pb(r.gf()),r.st.erase(r.st.begin());
    reverse(all(xs));
    for(auto &x : xs){
        umin(ans,1ll*k*x+b);
        k--;b+=x;
    }
    cout<<ans;
    return 0;
}
/*
#fwxpd bf
fwxpdbf
dpinbmcrfwxpdbf
*/

Compilation message

safety.cpp: In function 'void INPUT(bool)':
safety.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen(file".in","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
safety.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen(file".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 18108 KB Output is correct
2 Correct 225 ms 23856 KB Output is correct
3 Correct 221 ms 24684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 4 ms 848 KB Output is correct
29 Correct 4 ms 848 KB Output is correct
30 Correct 4 ms 848 KB Output is correct
31 Correct 4 ms 720 KB Output is correct
32 Correct 3 ms 720 KB Output is correct
33 Correct 3 ms 848 KB Output is correct
34 Correct 3 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 4 ms 848 KB Output is correct
35 Correct 4 ms 848 KB Output is correct
36 Correct 4 ms 848 KB Output is correct
37 Correct 4 ms 720 KB Output is correct
38 Correct 3 ms 720 KB Output is correct
39 Correct 3 ms 848 KB Output is correct
40 Correct 3 ms 848 KB Output is correct
41 Correct 4 ms 976 KB Output is correct
42 Correct 3 ms 764 KB Output is correct
43 Correct 3 ms 848 KB Output is correct
44 Correct 5 ms 840 KB Output is correct
45 Correct 3 ms 848 KB Output is correct
46 Correct 3 ms 840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 0 ms 208 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 0 ms 208 KB Output is correct
16 Correct 0 ms 208 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 0 ms 208 KB Output is correct
19 Correct 144 ms 18108 KB Output is correct
20 Correct 225 ms 23856 KB Output is correct
21 Correct 221 ms 24684 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 4 ms 848 KB Output is correct
38 Correct 4 ms 848 KB Output is correct
39 Correct 4 ms 848 KB Output is correct
40 Correct 4 ms 720 KB Output is correct
41 Correct 3 ms 720 KB Output is correct
42 Correct 3 ms 848 KB Output is correct
43 Correct 3 ms 848 KB Output is correct
44 Correct 4 ms 976 KB Output is correct
45 Correct 3 ms 764 KB Output is correct
46 Correct 3 ms 848 KB Output is correct
47 Correct 5 ms 840 KB Output is correct
48 Correct 3 ms 848 KB Output is correct
49 Correct 3 ms 840 KB Output is correct
50 Correct 250 ms 25240 KB Output is correct
51 Correct 180 ms 21560 KB Output is correct
52 Incorrect 139 ms 20964 KB Output isn't correct
53 Halted 0 ms 0 KB -