Submission #69276280


Source Code Expand

#pragma region MACRO
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vl = vector<ll>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i, n) for (auto &i : n)

template <class T1, class T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T1, class T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

struct init {
    init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        cerr << fixed << setprecision(15);
    }
} init_;

template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &a) { return out << a.first << ' ' << a.second; }
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &a) {
    for (auto it = a.begin(); it != a.end();) {
        out << *it;
        if (++it != a.end()) out << ' ';
    }
    return out;
}
template <typename T, size_t N>
ostream &operator<<(ostream &out, const array<T, N> &a) {
    for (auto it = a.begin(); it != a.end();) {
        out << *it;
        if (++it != a.end()) out << ' ';
    }
    return out;
}
template <typename T>
ostream &operator<<(ostream &out, const set<T> &a) {
    for (auto it = a.begin(); it != a.end();) {
        out << *it;
        if (++it != a.end()) out << ' ';
    }
    return out;
}
template <typename T, typename U>
ostream &operator<<(ostream &out, const map<T, U> &a) {
    for (auto it = a.begin(); it != a.end();) {
        out << *it;
        if (++it != a.end()) out << '\n';
    }
    return out;
}

#ifdef DEBUG
template <class T, class N>
void verr(const vector<T> &a, const N &n) {
    rep(i, n) cerr << a[i] << " ";
    cerr << endl;
}
template <class T, class N, size_t AN>
void verr(const array<T, AN> &a, const N &n) {
    rep(i, n) cerr << a[i] << " ";
    cerr << endl;
}
ll dbgt = 1;
void err() { cerr << "passed " << dbgt++ << endl; }
template <class H, class... T>
void err(H &&h, T &&...t) {
    cerr << h << (sizeof...(t) ? " " : "\n") << flush;
    if (sizeof...(t) > 0) err(forward<T>(t)...);
}
#else
void err() {}
template <class H, class... T>
void err(H &&h, T &&...t) {}
template <class H, class... T>
void verr(H &&h, T &&...t) {}
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
// const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

inline uint32_t pcg32() {
    static uint64_t x = 0x0123456789012345u;
    unsigned count = (unsigned)(x >> 61);
    x *= 3;
    x ^= x >> 22;
    return (uint32_t)(x >> (22 + count));
}
#pragma endregion

// 時間を出力
chrono::system_clock::time_point startTime, endTime;

// 経過時間(ms) を取得
int get_diff_time() {
    return chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - startTime).count();
}

// [0, a)の整数乱数
inline int get_randint(int a) {
    return (long long)pcg32() * a >> 32;
}

// [0, 1]の乱数
inline double get_randdouble() {
    return pcg32() / (double)numeric_limits<uint32_t>::max();
}

constexpr int LOG_NUM = 50000;
array<double, LOG_NUM> init_log_table() {
    array<double, LOG_NUM> table;
    rep(i, LOG_NUM) table[i] = -log(get_randdouble());
    return table;
}
const array<double, LOG_NUM> log_table = init_log_table();

// パラメータ
constexpr int TIME_LIMIT = 1950;
constexpr double START_TEMP = 100, END_TEMP = 1;
constexpr int N = 500, M = 50;
constexpr ll e15 = 1000000000000000LL;
constexpr ll e12 = 1000000000000LL;
constexpr ll L = e15 - 2 * e12, R = e15 + 2 * e12;

double get_time_progress() {
    return get_diff_time() / (double)TIME_LIMIT;
}


struct Input {
    Input() {}
    void read() {
        int n;
        cin >> n;
        
    }
};

using Score = int;

struct State {
    static Input ip;

    Score score;
    State() {
    }

    bool isBetterThan(const State &other) const {
        return score < other.score;
    }

    // 操作列を出力
    void output() const {
    }
};

Input State::ip;

struct ActionMove {
    static bool Run(State &s, const double& threshold, const double& temp) {
        const Score preScore = s.score;
        const int diff = 0;

        if(diff > threshold) {
            // 不採用
            return false;
        }

        // 操作列を変更

        return true;
    }
};


State simulated_annealing(State s) {
    State bestState = s;
    err("start sa");
    err("start score", s.score);

    double temp = START_TEMP;
    int sa_count = 0;
    int diff_time = get_diff_time();

    int accepted_count = 0;
    bool update_best = false;

    while (true) {
        constexpr int mesure_cycle = (1 << 16) - 1;
        if ((sa_count & mesure_cycle) == 0) {
            diff_time = get_diff_time();
            if (diff_time > TIME_LIMIT) break;
            if(diff_time > 1900) update_best = true;

            // 線形
            // temp = START_TEMP + (END_TEMP - START_TEMP) * get_time_progress();
            // 指数
            temp = START_TEMP * pow(END_TEMP / START_TEMP, get_time_progress());
        }

        // double threshold = log_table[get_randint(LOG_NUM)] * temp;
        double threshold = 0;

        const int randv = get_randint(10);
        bool res = false;
        if (randv < 1) {
            res |= ActionMove::Run(s, threshold, temp);
        } else if (randv < 10) {
        }
        accepted_count += res;

        if (update_best && s.isBetterThan(bestState)) {
            bestState = s;
        }
        sa_count++;
    }

    err("sa count", sa_count);
    err("state score", bestState.score);
    err("accepted count", accepted_count);

    return bestState;
}

void run_input() {
    // State::ip.read();
    ll n, m, l, u;
    cin >> n >> m >> l >> u;
}

void solve() {
    vl A;
    ll BN = 16, T = 29;

    vl btotal(BN);
    rep(b, BN) {
        rep(i, T) {
            if (A.size() == N - M) break;
            btotal[b]++;
            A.eb(1ll << (42 - b - 1));
        }
    }
    rep(i, M) A.eb(L);

    rep(i, N) {
        cout<< A[i] << " ";
    }
    cout << endl;

    // Bの入力
    vl B(M);
    rep(i, M) {
        cin >> B[i];
        B[i] -= L;
    }

    vl AF(N);
    rep(i, M) AF[N - M + i] = i + 1;

    vl bvals(M);
    vl brest = btotal;
    using Pair = pair<ll, ll>;
    priority_queue<Pair, vector<Pair>, less<Pair>> pq;
    rep(i, M) {
        pq.push({B[i], i});
    }

    rep(b, BN) {
        ll shift = 1ll << (42 - b - 1);
        priority_queue<Pair, vector<Pair>, less<Pair>> npq;

        while(!pq.empty()) {
            auto [bv, bi] = pq.top(); pq.pop();
            if(bv < shift ||brest[b] == 0) {
                npq.push({bv, bi});
                continue;
            }
            bvals[bi] += shift;
            AF[b * T + (btotal[b] - brest[b])] = bi + 1;
            brest[b]--;
            bv -= shift;
            if(bv >= shift && brest[b] > 0) {
                pq.push({bv, bi});
            } else {
                npq.push({bv, bi});
            }
        }
        swap(pq, npq);
        // ll cnt = 0;
        // rep(i, M) {
        //     if(brest[b] == 0) break;
        //     if (!(B[i] >> (42 - b - 1) & 1)) continue;

        //     bvals[i] += shift;
        //     AF[b * T + cnt] = i + 1;
        //     cnt++;
        //     brest[b]--;
        // }
    }

    // rep(i, M) {
    //     ll minE = INF, minBit = -1;
    //     ll bv = B[i];
    //     rep(bit, 1 << 9) {
    //         ll shift = bit << 42 - 9;
    //         ll e = abs(bv - shift);
    //         if(chmin(minE, e)) {
    //             minBit = bit;
    //         }
    //     }

    //     rep(bi, 9) {
    //         if((minBit >> 9 - bi - 1) & 1) {
    //             AF[bi * M + i] = i + 1;
    //         }
    //     }
    // }

    rep(i, N) cout<< AF[i] << " ";
    cout << endl;
}

void run() {
    run_input();
    solve();
}

int main() {
    startTime = chrono::system_clock::now();
#ifdef TUNE
    // params
#endif
    run();
}

Submission Info

Submission Time
Task A - Random Sum Game
User nrvft
Language C++ 23 (gcc 12.2)
Score 78438894205
Code Size 8949 Byte
Status AC
Exec Time 2 ms
Memory 4240 KiB

Compile Error

Main.cpp:1: warning: ignoring ‘#pragma region MACRO’ [-Wunknown-pragmas]
    1 | #pragma region MACRO
      | 
Main.cpp:125: warning: ignoring ‘#pragma endregion ’ [-Wunknown-pragmas]
  125 | #pragma endregion
      | 
Main.cpp: In static member function ‘static bool ActionMove::Run(State&, const double&, const double&)’:
Main.cpp:197:21: warning: unused variable ‘preScore’ [-Wunused-variable]
  197 |         const Score preScore = s.score;
      |                     ^~~~~~~~
Main.cpp:196:70: warning: unused parameter ‘temp’ [-Wunused-parameter]
  196 |     static bool Run(State &s, const double& threshold, const double& temp) {
      |                                                        ~~~~~~~~~~~~~~^~~~
Main.cpp: In instantiation of ‘void err(H&&, T&& ...) [with H = const char (&)[9]; T = {}]’:
Main.cpp:214:8:   required from here
Main.cpp:106:14: warning: unused parameter ‘h’ [-Wunused-parameter]
  106 | void err(H &&h, T &&...t) {}
      |          ~~~~^
Main.cpp: In instantiation of ‘void err(H&&, T&& ...) [with H = const char (&)[12]; T = {int&}]’:
Main.cpp:215:8:   required from here
Main.cpp:106:14: warning: unused parameter ‘h’ [-Wunused-parameter]
Main.cpp:106:21: warning: unused parameter ‘t#0’ [-Wunused-parameter]
  106 | void err(H &&h, T &&...t) {}
      |                 ~~~~^~~~
Main.cpp: In instantiation of ‘void err(H&&, T&& ...) [with H = const char (&)[9]; T = {int&}]’:
Main.cpp:254:8:   required from here
Main.cpp:106:14: warning: unused parameter ‘h’ [-Wunused-parameter]
  106 | void err(H &&h, T &&...t) {}
      |          ~~~~^
Main.cpp:106:21: warning: unused parameter ‘t#0’ [-Wunused-parameter]
  106 | void err(H &&h, T &&...t) {}
      |                 ~~~~^~~~
Main.cpp: In instantiation of ‘void err(H&&, T&& ...) [with H = const char (&)[15]; T = {int&}]’:
Main.cpp:256:8:   required from here
Main.cpp:106:14: warning: unused parameter ‘h’ [-Wunused-parameter]
  106 | void err(H &&h, T &&...t) {}
      |          ~~~~^
Main.cpp:106:21: warning: unused parameter ‘t#0’ [-Wunused-parameter]
  106 | void err(H &&h, T &&...t) {}
      |                 ~~~~^~~~

Judge Result

Set Name test_ALL
Score / Max Score 78438894205 / 150000000000
Status
AC × 150
Set Name Test Cases
test_ALL test_0000.txt, test_0001.txt, test_0002.txt, test_0003.txt, test_0004.txt, test_0005.txt, test_0006.txt, test_0007.txt, test_0008.txt, test_0009.txt, test_0010.txt, test_0011.txt, test_0012.txt, test_0013.txt, test_0014.txt, test_0015.txt, test_0016.txt, test_0017.txt, test_0018.txt, test_0019.txt, test_0020.txt, test_0021.txt, test_0022.txt, test_0023.txt, test_0024.txt, test_0025.txt, test_0026.txt, test_0027.txt, test_0028.txt, test_0029.txt, test_0030.txt, test_0031.txt, test_0032.txt, test_0033.txt, test_0034.txt, test_0035.txt, test_0036.txt, test_0037.txt, test_0038.txt, test_0039.txt, test_0040.txt, test_0041.txt, test_0042.txt, test_0043.txt, test_0044.txt, test_0045.txt, test_0046.txt, test_0047.txt, test_0048.txt, test_0049.txt, test_0050.txt, test_0051.txt, test_0052.txt, test_0053.txt, test_0054.txt, test_0055.txt, test_0056.txt, test_0057.txt, test_0058.txt, test_0059.txt, test_0060.txt, test_0061.txt, test_0062.txt, test_0063.txt, test_0064.txt, test_0065.txt, test_0066.txt, test_0067.txt, test_0068.txt, test_0069.txt, test_0070.txt, test_0071.txt, test_0072.txt, test_0073.txt, test_0074.txt, test_0075.txt, test_0076.txt, test_0077.txt, test_0078.txt, test_0079.txt, test_0080.txt, test_0081.txt, test_0082.txt, test_0083.txt, test_0084.txt, test_0085.txt, test_0086.txt, test_0087.txt, test_0088.txt, test_0089.txt, test_0090.txt, test_0091.txt, test_0092.txt, test_0093.txt, test_0094.txt, test_0095.txt, test_0096.txt, test_0097.txt, test_0098.txt, test_0099.txt, test_0100.txt, test_0101.txt, test_0102.txt, test_0103.txt, test_0104.txt, test_0105.txt, test_0106.txt, test_0107.txt, test_0108.txt, test_0109.txt, test_0110.txt, test_0111.txt, test_0112.txt, test_0113.txt, test_0114.txt, test_0115.txt, test_0116.txt, test_0117.txt, test_0118.txt, test_0119.txt, test_0120.txt, test_0121.txt, test_0122.txt, test_0123.txt, test_0124.txt, test_0125.txt, test_0126.txt, test_0127.txt, test_0128.txt, test_0129.txt, test_0130.txt, test_0131.txt, test_0132.txt, test_0133.txt, test_0134.txt, test_0135.txt, test_0136.txt, test_0137.txt, test_0138.txt, test_0139.txt, test_0140.txt, test_0141.txt, test_0142.txt, test_0143.txt, test_0144.txt, test_0145.txt, test_0146.txt, test_0147.txt, test_0148.txt, test_0149.txt
Case Name Status Exec Time Memory
test_0000.txt AC 2 ms 4120 KiB
test_0001.txt AC 2 ms 4004 KiB
test_0002.txt AC 2 ms 4068 KiB
test_0003.txt AC 2 ms 4096 KiB
test_0004.txt AC 2 ms 4220 KiB
test_0005.txt AC 2 ms 4184 KiB
test_0006.txt AC 2 ms 4120 KiB
test_0007.txt AC 2 ms 4124 KiB
test_0008.txt AC 2 ms 4000 KiB
test_0009.txt AC 2 ms 4088 KiB
test_0010.txt AC 2 ms 4180 KiB
test_0011.txt AC 2 ms 4172 KiB
test_0012.txt AC 2 ms 4004 KiB
test_0013.txt AC 2 ms 4068 KiB
test_0014.txt AC 2 ms 4240 KiB
test_0015.txt AC 2 ms 4068 KiB
test_0016.txt AC 2 ms 4232 KiB
test_0017.txt AC 2 ms 4172 KiB
test_0018.txt AC 2 ms 4096 KiB
test_0019.txt AC 2 ms 4176 KiB
test_0020.txt AC 2 ms 4236 KiB
test_0021.txt AC 2 ms 4148 KiB
test_0022.txt AC 2 ms 4116 KiB
test_0023.txt AC 2 ms 4132 KiB
test_0024.txt AC 2 ms 4116 KiB
test_0025.txt AC 2 ms 4172 KiB
test_0026.txt AC 2 ms 4132 KiB
test_0027.txt AC 2 ms 4120 KiB
test_0028.txt AC 2 ms 4092 KiB
test_0029.txt AC 2 ms 4176 KiB
test_0030.txt AC 2 ms 4116 KiB
test_0031.txt AC 2 ms 4108 KiB
test_0032.txt AC 2 ms 4220 KiB
test_0033.txt AC 2 ms 4116 KiB
test_0034.txt AC 2 ms 4224 KiB
test_0035.txt AC 2 ms 4172 KiB
test_0036.txt AC 2 ms 4064 KiB
test_0037.txt AC 2 ms 4064 KiB
test_0038.txt AC 2 ms 4172 KiB
test_0039.txt AC 2 ms 4124 KiB
test_0040.txt AC 2 ms 4220 KiB
test_0041.txt AC 2 ms 4232 KiB
test_0042.txt AC 2 ms 4092 KiB
test_0043.txt AC 2 ms 4168 KiB
test_0044.txt AC 2 ms 4232 KiB
test_0045.txt AC 2 ms 4132 KiB
test_0046.txt AC 2 ms 3996 KiB
test_0047.txt AC 2 ms 4152 KiB
test_0048.txt AC 2 ms 4120 KiB
test_0049.txt AC 2 ms 4124 KiB
test_0050.txt AC 2 ms 4056 KiB
test_0051.txt AC 2 ms 4120 KiB
test_0052.txt AC 2 ms 4020 KiB
test_0053.txt AC 2 ms 4120 KiB
test_0054.txt AC 2 ms 4216 KiB
test_0055.txt AC 2 ms 4236 KiB
test_0056.txt AC 2 ms 4168 KiB
test_0057.txt AC 2 ms 4236 KiB
test_0058.txt AC 2 ms 4092 KiB
test_0059.txt AC 2 ms 4108 KiB
test_0060.txt AC 2 ms 4148 KiB
test_0061.txt AC 2 ms 4108 KiB
test_0062.txt AC 2 ms 4132 KiB
test_0063.txt AC 2 ms 4232 KiB
test_0064.txt AC 2 ms 4232 KiB
test_0065.txt AC 2 ms 4176 KiB
test_0066.txt AC 2 ms 4116 KiB
test_0067.txt AC 2 ms 4224 KiB
test_0068.txt AC 2 ms 4124 KiB
test_0069.txt AC 2 ms 4236 KiB
test_0070.txt AC 2 ms 4164 KiB
test_0071.txt AC 2 ms 4164 KiB
test_0072.txt AC 2 ms 4068 KiB
test_0073.txt AC 2 ms 4132 KiB
test_0074.txt AC 2 ms 4172 KiB
test_0075.txt AC 2 ms 4220 KiB
test_0076.txt AC 2 ms 4216 KiB
test_0077.txt AC 2 ms 4064 KiB
test_0078.txt AC 2 ms 4068 KiB
test_0079.txt AC 2 ms 4124 KiB
test_0080.txt AC 2 ms 4172 KiB
test_0081.txt AC 2 ms 4180 KiB
test_0082.txt AC 2 ms 4124 KiB
test_0083.txt AC 2 ms 4120 KiB
test_0084.txt AC 2 ms 4120 KiB
test_0085.txt AC 2 ms 4232 KiB
test_0086.txt AC 2 ms 4176 KiB
test_0087.txt AC 2 ms 4132 KiB
test_0088.txt AC 2 ms 4224 KiB
test_0089.txt AC 2 ms 4060 KiB
test_0090.txt AC 2 ms 4112 KiB
test_0091.txt AC 2 ms 4112 KiB
test_0092.txt AC 2 ms 4220 KiB
test_0093.txt AC 2 ms 4236 KiB
test_0094.txt AC 2 ms 4224 KiB
test_0095.txt AC 2 ms 4224 KiB
test_0096.txt AC 2 ms 4132 KiB
test_0097.txt AC 2 ms 4108 KiB
test_0098.txt AC 2 ms 4216 KiB
test_0099.txt AC 2 ms 4120 KiB
test_0100.txt AC 2 ms 4096 KiB
test_0101.txt AC 2 ms 4220 KiB
test_0102.txt AC 2 ms 4120 KiB
test_0103.txt AC 2 ms 4180 KiB
test_0104.txt AC 2 ms 4232 KiB
test_0105.txt AC 2 ms 4000 KiB
test_0106.txt AC 2 ms 4144 KiB
test_0107.txt AC 2 ms 4056 KiB
test_0108.txt AC 2 ms 4120 KiB
test_0109.txt AC 2 ms 4132 KiB
test_0110.txt AC 2 ms 4112 KiB
test_0111.txt AC 2 ms 4220 KiB
test_0112.txt AC 2 ms 4112 KiB
test_0113.txt AC 2 ms 4096 KiB
test_0114.txt AC 2 ms 4120 KiB
test_0115.txt AC 2 ms 4216 KiB
test_0116.txt AC 2 ms 4068 KiB
test_0117.txt AC 2 ms 4220 KiB
test_0118.txt AC 2 ms 4132 KiB
test_0119.txt AC 2 ms 4148 KiB
test_0120.txt AC 2 ms 4176 KiB
test_0121.txt AC 2 ms 4152 KiB
test_0122.txt AC 2 ms 4000 KiB
test_0123.txt AC 2 ms 4000 KiB
test_0124.txt AC 2 ms 4236 KiB
test_0125.txt AC 2 ms 4180 KiB
test_0126.txt AC 2 ms 4232 KiB
test_0127.txt AC 2 ms 4064 KiB
test_0128.txt AC 2 ms 4068 KiB
test_0129.txt AC 2 ms 4232 KiB
test_0130.txt AC 2 ms 4092 KiB
test_0131.txt AC 2 ms 4132 KiB
test_0132.txt AC 2 ms 4124 KiB
test_0133.txt AC 2 ms 4004 KiB
test_0134.txt AC 2 ms 4112 KiB
test_0135.txt AC 2 ms 4068 KiB
test_0136.txt AC 2 ms 4104 KiB
test_0137.txt AC 2 ms 4120 KiB
test_0138.txt AC 2 ms 4000 KiB
test_0139.txt AC 2 ms 4116 KiB
test_0140.txt AC 2 ms 4064 KiB
test_0141.txt AC 2 ms 4148 KiB
test_0142.txt AC 2 ms 4092 KiB
test_0143.txt AC 2 ms 4080 KiB
test_0144.txt AC 2 ms 4236 KiB
test_0145.txt AC 2 ms 4220 KiB
test_0146.txt AC 2 ms 4108 KiB
test_0147.txt AC 2 ms 4120 KiB
test_0148.txt AC 2 ms 4116 KiB
test_0149.txt AC 2 ms 4168 KiB