Submission #400697

# Submission time Handle Problem Language Result Execution time Memory
400697 2021-05-08T14:09:01 Z cpp219 Divide and conquer (IZhO14_divide) C++14
48 / 100
1000 ms 4168 KB
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 3e5 + 9;
const ll inf = 1e16 + 7;
const ll Log2 = 21;
struct mine{
    ll pos,g,e;
};
mine a[N];
ll n,gold[N],sum[N];
vector<ll> v;
bool lf(mine a,mine b){
    return a.pos < b.pos;
}

ll Find(ll x){
    return lower_bound(v.begin(),v.end(),x) - v.begin() + 1;
}

void compress(){
    sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end()) - v.begin());
}

ll st[4*N];

void upd(ll id,ll l,ll r,ll u,ll val){
    if (u < l||r < u) return;
    if (l == r){
        st[id] = val; return;
    }
    ll mid = (l + r)/2;
    upd(id*2,l,mid,u,val); upd(id*2 + 1,mid + 1,r,u,val);
    st[id] = max(st[id*2],st[id*2 + 1]);
}

ll Get(ll id,ll l,ll r,ll u,ll v){
    if (v < l||r < u) return 0;
    if (u <= l&&r <= v) return st[id];
    ll mid = (l + r)/2;
    return max(Get(id*2,l,mid,u,v),Get(id*2 + 1,mid + 1,r,u,v));
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "tst"
    if (fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        //freopen(task".out","w",stdout);
    }
    cin>>n;
    for (ll i = 1;i <= n;i++) cin>>a[i].pos>>a[i].g>>a[i].e;
    sort(a + 1,a + n + 1,lf);
    for (ll i = 1;i <= n;i++){
        gold[i] = gold[i - 1] + a[i].g; sum[i] = sum[i - 1] + a[i].e;
        v.push_back(sum[i] - a[i].pos); v.push_back(sum[i] - a[i].pos - a[i].e);
    }
    compress(); ll ans = 0;
    for (ll i = 1;i <= n;i++){
        ans = max(ans,a[i].g);
        for (ll j = i + 1;j <= n;j++) if (sum[j] - sum[i - 1] >= a[j].pos - a[i].pos)
            ans = max(ans,gold[j] - gold[i - 1]);
    }
    cout<<ans;
}

Compilation message

divide.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
divide.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
divide.cpp: In function 'int main()':
divide.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   56 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 3 ms 460 KB Output is correct
22 Correct 5 ms 460 KB Output is correct
23 Correct 24 ms 972 KB Output is correct
24 Correct 24 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 3 ms 460 KB Output is correct
22 Correct 5 ms 460 KB Output is correct
23 Correct 24 ms 972 KB Output is correct
24 Correct 24 ms 972 KB Output is correct
25 Correct 18 ms 716 KB Output is correct
26 Correct 67 ms 1104 KB Output is correct
27 Correct 68 ms 1224 KB Output is correct
28 Execution timed out 1077 ms 4168 KB Time limit exceeded
29 Halted 0 ms 0 KB -