답안 #980200

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
980200 2024-05-12T00:59:45 Z vjudge1 봉쇄 시간 (IOI23_closing) C++17
35 / 100
1000 ms 26308 KB
#include <bits/stdc++.h>
#define endl '\n'
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define fo(i,n) for(auto i =0 ; i < n;i++)
#define fore(i,l,r) for(auto i = l; i < r;i++)
#define forex(i,r,l) for(auto i = r; i >= l; i--)
#define ffo(i,n) forex(i,n-1,0)
#define all(x) x.begin(),x.end()
#define lsb(x) x&(-x)
#define sz(x) (int)x.size()
#define gcd(a,b) __gcd(a,b)
#define vii vector<ii>
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>;using ii = pair<int,int>;using mii = map<int,int>;
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
const int LOG = 13;
struct fenwick{
    vector<ll> ft;int n;
    fenwick(int kkk){n=kkk;ft.resize(n+2,0);}
    void update(int idx, ll val){for(; idx < n; idx += lsb(idx))ft[idx]+=val;}
    ll query(int idx){ll res = 0;for(;idx>0;idx-=lsb(idx))res+=ft[idx];return res;}
    ll query(int l, int r ){if(l>r)return 0;return query(r) - query(l-1);}
    int lwb(ll v){
        ll sum = 0;int pos=0;
        for(int i=LOG; i>=0; i--)
            if(pos + (1 << i) < n and sum + ft[pos + (1 << i)] < v){
                sum += ft[pos + (1 << i)];pos += (1 << i);
            }return pos + 1;
    }
};
int max_score(int n, int x, int y, ll k, vector<int> u, vector<int> v, vector<int> w){
    ll suf[n+1]{}, pre[n+1]{};
    fore(i,1,n)pre[i] = (i ? w[i-1] : 0) + (i ? pre[i-1] : 0);
    ffo(i,n-1)suf[i] = w[i] + suf[i+1];
    ll disx[n+1]{};
    for(int i = x-1; i >= 0; i--)disx[i] = disx[i+1] + w[i];
    ll disy[n+1]{} , ans = 0;
    for(int i = y+1; i <= n-1;i++)disy[i] = disy[i-1] + w[i-1];
    int tot = 0;
    vi ord;fo(i,x+1)ord.pb(disx[i]);fore(i,y,n)ord.pb(disy[i]);
    sort(all(ord)) ;
    // for(int v : ord) cout << v << " ";cout<<endl;
    for(int j = x; j <= n-1; j++ ){
        // cout << "Nuevo indice " << j << endl;
        map<int, int> indices;
        fo(i, sz(ord))indices[ord[i]]=0;
        ans+= pre[j] - pre[x];
        fenwick cnt(2*n+1), sum(2*n+1);
        for(int l=y;l>=0;l--){
            if(l>j)ans+=suf[l]- suf[y];
            else{
                if(l>x){
                    if(j>=l){
                        if(suf[l]-suf[y] > pre[l] - pre[x]){
                            ans -= pre[l] - pre[x];
                            ans+=suf[l]-suf[y];
                        }
                    }
                    else ans+= suf[l]-suf[y];
                }
                else{ans+=suf[l]-suf[y];if(l>=j)ans-=suf[l] - suf[x];}
            }
        }
        for(int i = max(y+1,j+1); i <= n-1; i++){
            // disy[i]
            // cout << disy[i] << " ";
            int pos = lower_bound(all(ord), disy[i])-ord.begin() ,pos2 = pos;
            pos+=indices[ord[pos]];indices[ord[pos2]]++;
            // inserto esta, 1-indexado
            cnt.update(pos+1, +1);
            sum.update(pos+1, +disy[i]);
        }
        // cout<<endl;
        for(int l =0;l<=y;l++){
            if(ans <= k){
                // int lb = 1, rb = cnt.query(1, 2*n);
                // // cout << "Busqueda binaria " << endl;
                // while(lb<=rb){
                //     int mid = (lb+rb)/2;
                //     // ahora quiero poner mid nuevos
                //     // cout << lb << " " << rb << " " << mid << endl;
                //     int pos = cnt.lwb(mid);
                //     // cout << "Posicion del ultimo valor que debería poner" << endl;
                //     // cout << pos << endl;
                //     // cout << "Valor" << endl;
                //     // cout << ord[pos-1] << endl;
                //     ll con = sum.query(1, pos-1) + ((mid-cnt.query(1,pos-1))* ord[pos-1]);
                //     // cout << "Lo que me cuesta" << endl;
                //     // cout << con << endl;
                //     if(con+ans <= k) lb = mid+1;
                //     else rb = mid-1;
                // }
                int rb = sum.lwb(k-ans+1) - 1;
                rb = cnt.query(1, rb);
                // cout << j << " " << l << " " << rb << endl; 
                tot = max(tot, j-x+1 + y-l+1 + rb + max(j-y, 0) + max(x-l, 0));
                // cout << j-x+1 + y-l+1 + rb + max(j-y, 0) + max(x-l, 0) << endl;
            }
            // cout << ans << " " << j << " " << l << " " << lb << " " << rb << endl;
            // for(int idx = 1; idx <= 2*n;idx++)cout << cnt.query(idx,idx) << " ";cout << endl;
            // for(int idx = 1; idx <= 2*n; idx ++ )cout << sum.query(idx,idx) << " "; cout << endl;
            // cout << endl << endl;
            if(l>j)ans-=suf[l]- suf[y];
            else{
                if(l>x){
                    if(j>=l){
                        if(suf[l]-suf[y] > pre[l] - pre[x]){
                            ans += pre[l] - pre[x];
                            ans -=suf[l]-suf[y];
                        }
                    }
                    else ans -= suf[l]-suf[y];
                }
                else{ans-=suf[l]-suf[y];if(l>=j)ans+=suf[l] - suf[x];}
            }
            // insertar disx[l]
            int pos = lower_bound(all(ord), disx[l])-ord.begin(),pos2=pos;
            // inserto esta, 1-indexado
            if(l <= x-1){
                pos+=indices[ord[pos]];indices[ord[pos2]]++;
                cnt.update(pos+1, +1);
                sum.update(pos+1, +disx[l]);
            }
        }
    }
    return tot;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1074 ms 26308 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 10 ms 348 KB Output is correct
20 Correct 17 ms 600 KB Output is correct
21 Correct 12 ms 600 KB Output is correct
22 Correct 12 ms 476 KB Output is correct
23 Correct 4 ms 344 KB Output is correct
24 Correct 4 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 10 ms 348 KB Output is correct
20 Correct 17 ms 600 KB Output is correct
21 Correct 12 ms 600 KB Output is correct
22 Correct 12 ms 476 KB Output is correct
23 Correct 4 ms 344 KB Output is correct
24 Correct 4 ms 344 KB Output is correct
25 Correct 7 ms 348 KB Output is correct
26 Correct 603 ms 604 KB Output is correct
27 Correct 425 ms 852 KB Output is correct
28 Correct 270 ms 604 KB Output is correct
29 Correct 657 ms 852 KB Output is correct
30 Correct 513 ms 808 KB Output is correct
31 Correct 119 ms 604 KB Output is correct
32 Correct 123 ms 712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -