Submission #1330573

#TimeUsernameProblemLanguageResultExecution timeMemory
1330573nicolo_010Treasure (IOI24_treasure)C++20
24 / 100
444 ms8716 KiB
#include "treasure.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

ll f(int x, int y) {
    return y+1000000000ll*x;
}

const int B = 3; //Blocks jiji

std::vector<int> encode(std::vector<std::pair<int, int>> P) {
    int n = P.size();
    vector<int> a;
    for (int i=0; i<n; i++) {
        ll num = f(P[i].first, P[i].second);
        //cout << num << endl;
        for (int c=0; c<(18+B-1)/B; c++) {
            ll s=0;
            ll pw=1;
            for (int j=0; j<B; j++) {
                s += (num%(10))*pw;
                pw *= 10;
                num /= 10;
            }
            int k = i;
            for (int j=0; j<5; j++) {
                s += (k%10)*pw;
                pw *= 10;
                k /= 10;
            }
            s += c*pw;
            a.push_back(s);
        }
    }
    return a;
}

std::vector<std::pair<int, int>> decode(std::vector<int> S) {
    vector<pii> a;
    map<int, ll> mp;
    for (auto s : S) {
        int num=0;
        ll pw=1;
        for (int i=0; i<B; i++) {
            num += (s%10)*pw;
            pw *= 10;
            s /= 10;
        }
        int idx=0;

        for (int i=0; i<5; i++) {
            idx += (s%10)*pw;
            pw *= 10;
            s /= 10;
        }
        int c = s;
        pw=1;
        for (int i=0; i<c; i++) {
            pw *= 1000;
        }
        //cout << og << " " << num << " " << idx << " " << pw << " " << c << "\n";
        mp[idx] += num*pw;
    }
    for (auto p : mp) {
        int y = (p.second%((ll)1e9));
        ll k = p.second;
        k /= ((ll)1e9);
        int x = k;
        a.push_back({x, y});
    }
    return a;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...