답안 #118112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118112 2019-06-18T08:02:57 Z JohnTitor Semiexpress (JOI17_semiexpress) C++11
100 / 100
16 ms 3712 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
#define taskname "Semiexp"
ll n;
int m, k;
ll t;
ll a, b, c;
ll ans=0;
ll s[3001];
vector <vector <ll>> p;
void prepare(ll x, ll t){
    vector <ll> all;
    ll sum=0;
    while(all.size()<=k){
        all.pb(t/a+1);
        t-=all.back()*c;
        sum+=all.back();
        if(sum>=x){
            all.back()-=sum-x;
            break;
        }
        if(t<0) break;
    }
//    for(ll x: all) bug(x);
    reverse(all.begin(), all.end());
    assert(is_sorted(all.begin(), all.end()));
    ans+=all.back();
    all.pop_back();
    if(!all.empty()) p.pb(all);
}
class cmp{
public:
    bool operator ()(int a, int b){
        return p[a].back()<p[b].back();
    }
};
priority_queue <int, vector <int>, cmp> q;
int main(){
    #ifdef Aria
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Aria
    read(n);
    read(m);
    read(k);
    read(a);
    read(b);
    read(c);
    read(t);
    FOR(i, 1, m) read(s[i]);
    k-=m;
    FFOR(i, 1, m){
        ll r=t-(s[i]-1)*b;
        if(r<0) break;
        prepare(s[i+1]-s[i], r);
    }
    if((n-1)*b>t) ans--;
    FFOR(i, 0, p.size()) q.push(i);
    FOR(i, 1, k){
        if(q.empty()) break;
        int u=q.top();
        q.pop();
        ans+=p[u].back();
        p[u].pop_back();
        if(!p[u].empty()) q.push(u);
    }
    writeln(ans);
}

Compilation message

semiexpress.cpp: In function 'void prepare(ll, ll)':
semiexpress.cpp:30:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(all.size()<=k){
           ~~~~~~~~~~^~~
semiexpress.cpp: In function 'int main()':
semiexpress.cpp:4:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FFOR(i, j, k) for(int i=(j); i<(k); i++)
                                       ^
semiexpress.cpp:74:5: note: in expansion of macro 'FFOR'
     FFOR(i, 0, p.size()) q.push(i);
     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 260 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 260 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 276 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 524 KB Output is correct
23 Correct 16 ms 3712 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 11 ms 2560 KB Output is correct
30 Correct 7 ms 1792 KB Output is correct