Submission #925001

# Submission time Handle Problem Language Result Execution time Memory
925001 2024-02-10T12:24:33 Z parlimoos RLE (BOI06_rle) C++14
5 / 100
892 ms 94820 KB
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<ll , x>
#define endl '\n'

int n , m;
vector<arr(2)> bls;
set<arr(2)> ord;
int infs[100000];
int mns[2000000][2];
vector<int> o;

void add(int c , int x){
    int len = (int)bls.size();
    if(!bls.empty() and bls[len - 1][0] == c) bls[len - 1][1] += (1ll * x);
    else bls.pb({c , x});
}
int clc(int i , bool sgn){
    if(sgn) return (3 * ((bls[i][1] + n - 1) / n));
    int res = 3 * (bls[i][1] / (n + 2));
    if(bls[i][1] % (n + 2) > 2) res += 3;
    else res += bls[i][1] % (n + 2);
    return res; 
}
void clcO(int i , int sgn){
    if(sgn == bls[i][0]){
        int d = bls[i][1];
        while(d > 0) o.pb(min(n , d) - 1) , o.pb(sgn) , o.pb(sgn) , d -= min(n , d);
    }else{
        int d = bls[i][1];
        while(d > 3) o.pb(min(n + 2 , d) - 3) , o.pb(bls[i][0]) , o.pb(sgn) , d -= min(n + 2 , d);
        for(int j = 0 ; j < d ; j++) o.pb(bls[i][0]);
    }
}
void f(){
    ord.insert({0 , 0});
    for(int i = 1 ; i < n ; i++) ord.insert({3 , i}) , infs[i] = 3;
    int len = (int)bls.size();
    for(int i = 0 ; i < len ; i++){
        int d = clc(i , 1) - clc(i , 0);
        arr(2) itr = (*ord.find({infs[bls[i][0]] , bls[i][0]}));
        ord.erase(itr);

        infs[bls[i][0]] += d;
        itr[0] += d;
        ord.insert(itr);
        mns[i][0] = (*ord.bg())[1] , mns[i][1] = (*ord.bg())[0];
        if(itr[0] > mns[i][1] + 3){
            ord.erase(itr);
            itr[0] = mns[i][1] + 3;
            ord.insert(itr);
        }
    }
    int e = mns[len - 1][0] , sz = mns[len - 1][1];
    for(int i = len - 1 ; i >= 0 ; i--){
        clcO(i , e);
        if(i == 0){
            if(e != 0) o.pb(0) , o.pb(e) , o.pb(0);
        }else{
            int d = 0;
            if(bls[i][0] == e) d = clc(i , 1) - clc(i , 0);
            if(mns[i - 1][1] + 3 + d == sz) o.pb(0) , o.pb(e) , o.pb(mns[i - 1][0]) , e = mns[i - 1][0] , sz = mns[i - 1][1];
            else sz -= d;
        }
    }
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int e = 0;
    cin >> n >> m;
    for(int i = 0 ; i < m ;){
        int d;
        cin >> d;
        if(d != e) add(d , 1) , i++;
        else{
            int d1 , d2;
            cin >> d1 >> d2;
            if(d1 != e and d2 == 0) e = d1;
            else if(d1 == e) add(e , d2 + 1);
            else if(d1 != e and d2 > 0) add(d1 , d2 + 3);
            i += 3;
        }
    }
    f();
    cout << (int)o.size() << endl;
    for(int i = (int)o.size() - 1 ; i >= 0 ; i--) cout << o[i] << " ";
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB code is not the shortest
2 Incorrect 1 ms 500 KB code is not the shortest
3 Incorrect 1 ms 348 KB code is not the shortest
4 Incorrect 1 ms 344 KB code is not the shortest
5 Incorrect 1 ms 348 KB code is not the shortest
6 Incorrect 13 ms 1628 KB code is not the shortest
7 Incorrect 96 ms 11216 KB code is not the shortest
8 Incorrect 123 ms 16456 KB code is not the shortest
9 Incorrect 247 ms 39088 KB code is not the shortest
10 Incorrect 91 ms 10820 KB code is not the shortest
11 Incorrect 79 ms 11560 KB code is not the shortest
12 Incorrect 182 ms 29620 KB code is not the shortest
13 Incorrect 196 ms 22792 KB code is not the shortest
14 Incorrect 98 ms 13756 KB code is not the shortest
15 Incorrect 50 ms 8908 KB code is not the shortest
16 Correct 203 ms 24652 KB Output is correct
17 Incorrect 264 ms 29660 KB code is not the shortest
18 Incorrect 278 ms 29632 KB the output code does not encode the input sequence
19 Incorrect 892 ms 94532 KB code is not the shortest
20 Incorrect 854 ms 94820 KB code is not the shortest