Submission #1080206

# Submission time Handle Problem Language Result Execution time Memory
1080206 2024-08-29T08:00:16 Z GrindMachine Comparing Plants (IOI20_plants) C++17
14 / 100
4000 ms 21896 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define endl '\n'
#define conts continue
#define sz(a) (int)a.size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; ++i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &x, T y){
    x = min(x,y);
}

template<typename T>
void amax(T &x, T y){
    x = max(x,y);
}

template<typename A,typename B>
string to_string(pair<A,B> p);

string to_string(const string &s){
    return "'"+s+"'";
}

string to_string(const char* s){
    return to_string((string)s);
}

string to_string(bool b){
    return b?"true":"false";
}

template<typename A>
string to_string(A v){
    string res = "{";
    trav(x,v){
        res += to_string(x)+",";
    }
    if(res.back() == ',') res.pop_back();
    res += "}";
    return res;
}

template<typename A,typename B>
string to_string(pair<A,B> p){
    return "("+to_string(p.ff)+","+to_string(p.ss)+")";
}

#define debug(x) cout << "[" << #x << "]: "; cout << to_string(x) << endl

const int MOD = 1e9 + 7;
const int N = 1<<18;
const int inf1 = 1e9 + 5;
const ll inf2 = (ll)1e18 + 5;

#include "plants.h"

pii d_neutral = {inf1,-1};
vector<pii> tr(4*N,d_neutral);
vector<int> lz(4*N);

void propagate(int x, int lx, int rx){
    int v = lz[x];
    tr[x].ff += v;

    if(rx-lx > 1){
        lz[x<<1] += v;
        lz[x<<1|1] += v;
    }

    lz[x] = 0;
}

void rupd(int x, int lx, int rx, int l, int r, int v){
    propagate(x,lx,rx);

    if(lx >= r or rx <= l) return;
    if(lx >= l and rx <= r){
        lz[x] = v;
        propagate(x,lx,rx);
        return;
    }

    int mid = (lx+rx)>>1;
    rupd(x<<1,lx,mid,l,r,v);
    rupd(x<<1|1,mid,rx,l,r,v);

    tr[x] = min(tr[x<<1],tr[x<<1|1]);
}

void rupd(int l, int r, int v){
    rupd(1,0,N,l,r+1,v);
}

pii query(){
    propagate(1,0,N);
    return tr[1];
}

void build(int x, int lx, int rx, vector<int> &a){
    if(rx-lx == 1){
        if(lx < sz(a)){
            tr[x] = {a[lx],lx};
        }
        return;
    }

    int mid = (lx+rx) >> 1;
    build(x<<1,lx,mid,a);
    build(x<<1|1,mid,rx,a);
    tr[x] = min(tr[x<<1],tr[x<<1|1]);
}

void build(vector<int> &a){
    build(1,0,N,a);
}

vector<int> id(N);

void init(int k, std::vector<int> a) {
    k--;
    int n = sz(a);
    build(a);

    int iter = 0;
    int rem_cnt = 0;

    auto rem = [&](int i){
        rem_cnt++;
        if(i-k >= 0){
            rupd(i-k,i-1,-1);
        }
        else{
            rupd(0,i-1,-1);
            rupd(i-k+n,n-1,-1);
        }
    };

    while(rem_cnt < n){
        iter++;

        vector<int> zeros;
        while(true){
            auto [mn,ind] = query();
            if(mn == 0){
                zeros.pb(ind);
                rupd(ind,ind,inf1);
            }
            else{
                break;
            }
        }

        sort(all(zeros));

        if(sz(zeros) == 1){
            trav(i,zeros){
                rem(i);
                id[i] = iter;
            }
        }
        else{
            int pz = zeros.back();
            trav(i,zeros){
                int d = (i-pz+n)%n;
                if(d > k){
                    rem(i);
                    id[i] = iter;
                }
                else{
                    rupd(i,i,-inf1);
                }

                pz = i;
            }
        }
    }
}

int compare_plants(int x, int y) {
    if(id[x] < id[y]) return 1;
    if(id[x] > id[y]) return -1;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 13664 KB Output is correct
2 Correct 12 ms 13664 KB Output is correct
3 Correct 8 ms 13660 KB Output is correct
4 Incorrect 10 ms 13660 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 13660 KB Output is correct
2 Correct 8 ms 13656 KB Output is correct
3 Correct 13 ms 13660 KB Output is correct
4 Correct 13 ms 13796 KB Output is correct
5 Correct 10 ms 13660 KB Output is correct
6 Correct 9 ms 13660 KB Output is correct
7 Correct 81 ms 17700 KB Output is correct
8 Correct 8 ms 13804 KB Output is correct
9 Correct 13 ms 13804 KB Output is correct
10 Correct 59 ms 17708 KB Output is correct
11 Correct 3569 ms 17696 KB Output is correct
12 Correct 44 ms 17820 KB Output is correct
13 Correct 64 ms 17900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 13660 KB Output is correct
2 Correct 8 ms 13656 KB Output is correct
3 Correct 13 ms 13660 KB Output is correct
4 Correct 13 ms 13796 KB Output is correct
5 Correct 10 ms 13660 KB Output is correct
6 Correct 9 ms 13660 KB Output is correct
7 Correct 81 ms 17700 KB Output is correct
8 Correct 8 ms 13804 KB Output is correct
9 Correct 13 ms 13804 KB Output is correct
10 Correct 59 ms 17708 KB Output is correct
11 Correct 3569 ms 17696 KB Output is correct
12 Correct 44 ms 17820 KB Output is correct
13 Correct 64 ms 17900 KB Output is correct
14 Correct 82 ms 18048 KB Output is correct
15 Correct 380 ms 19744 KB Output is correct
16 Correct 86 ms 18772 KB Output is correct
17 Correct 415 ms 21376 KB Output is correct
18 Execution timed out 4037 ms 21896 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 13708 KB Output is correct
2 Correct 8 ms 13656 KB Output is correct
3 Correct 122 ms 17424 KB Output is correct
4 Execution timed out 4051 ms 20272 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 13660 KB Output is correct
2 Correct 7 ms 13660 KB Output is correct
3 Incorrect 11 ms 13660 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 13660 KB Output is correct
2 Correct 6 ms 13660 KB Output is correct
3 Incorrect 7 ms 13660 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 13664 KB Output is correct
2 Correct 12 ms 13664 KB Output is correct
3 Correct 8 ms 13660 KB Output is correct
4 Incorrect 10 ms 13660 KB Output isn't correct
5 Halted 0 ms 0 KB -