Submission #14820134


Source Code Expand

Copy
// May this submission get accepted
#include <bits/stdc++.h>

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using namespace std;

// AtCoder/Codeforces 用 デバッグ検知
#ifdef ONLINE_JUDGE
constexpr bool DEBUG_MODE = false;
#else
constexpr bool DEBUG_MODE = true;
#endif

// エイリアス (補完・コンパイルが重くなる)
// #include <boost/multiprecision/cpp_int.hpp>
// using mll = boost::multiprecision::cpp_int;

// 汎用マクロ
#define ALLOF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define FOREACH(i,q) for (auto &i : q)
template<typename T, typename U> bool chmax(T &a, const U b) { if (a < b) {a = b; return true;} return false; }
template<typename T, typename U> bool chmin(T &a, const U b) { if (a > b) {a = b; return true;} return false; }
constexpr int INF = numeric_limits<int>::max();
constexpr long long LINF = numeric_limits<long long>::max();
constexpr long double EPS = 1e-10L;
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define IIF(q,t,f) ((q) ? (t) : (f))
#define DUMP(q) DUMP_FUNC(q, #q, __FILE__, __LINE__)
template <typename T> void DUMP_PROC(T x) { if (is_integral<T>() || is_floating_point<T>()) cerr << "\e[32m" << x << "\e[m"; else cerr << x; }
template<> void DUMP_PROC<char>(char x) { cerr << "\e[36m\'" << x << "\'\e[m"; }
template<> void DUMP_PROC<string>(string x) { cerr << "\e[33m\"" << x << "\"\e[m"; }
template <typename T, typename U> void DUMP_PROC(pair<T, U> x) { cerr << "{"; DUMP_PROC(x.first); cerr << ", "; DUMP_PROC(x.second); cerr << "}"; }
template <typename ...T, typename U, U... Seq> void DUMP_PROC(tuple<T...> &x, integer_sequence<U, Seq...>) { (void)(int[]){(cerr << ((const char*[]){"", ", "})[!!Seq] << (DUMP_PROC(get<Seq>(x)), ""), 0)...}; }
template <typename ...T> void DUMP_PROC(tuple<T...> x) {cerr << "{"; DUMP_PROC(x, index_sequence_for<T...>()); cerr << "}";}
template <typename T> void DUMP_PROC(vector<T> x) { cerr << "["; for (auto &xi : x) { DUMP_PROC(xi); cerr << (&xi != &*x.rbegin()?", ":""); } cerr << "]"; }
template <typename T> void DUMP_FUNC(T x, const char* name, const char* fn, int ln) { cerr << "\e[32m[DEBUG]\e[m " << name << ": "; DUMP_PROC(x); cerr << " @ " << fn << "(" << ln << ")" << endl; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// 標準入出力
struct qin { // query input
    size_t sz;
    qin(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
qin in1; // input one
template <typename T> void say(const T x, const char* end = "\n") { cout << x << end; }
void say(const ld x, const char* end = "\n") { cout << setprecision(30) << x << end; }
template <typename T> void say(const vector<T> x, const char* sep = " ", const char* end = "\n") { REP(i, x.size()) { cout << x[i] << (i+1 == i_len ? end : sep); } }
template <typename T> void say(const vector<vector<T>> x, const char* sep = " ", const char* end = "\n") { REP(i, x.size()) { say(x[i], sep, end); } }

// モジュール
// [[LIBRARY]] marathon.cpp xor128.cpp
// [Inclusion] xor128.cpp
// XORShift 擬似乱数発生器
uint32_t xor128(void){
    static uint32_t x = 123456789;
    static uint32_t y = 362436069;
    static uint32_t z = 521288629;
    static uint32_t w = 88675123; 
    uint32_t t;

    t = x ^ (x << 11);
    x = y; y = z; z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));  
}
inline double rand_uniform(void) { return (double)xor128() / 0x100000000LL; }
template <typename T>
inline T rand_range(T min, T max) { return min + xor128() % (max - min + 1); }
inline bool rand_prob(double p) { return rand_uniform() < p; }

// [Inclusion] marathon.cpp
// 依存関係じゃないけどよほどでなければ一緒に使うのでxor128.cppを入れる
// マラソン用モジュール
namespace marathon {
    clock_t start_clock;
    constexpr double time_limit = 2; // 実行時間[s]より0.1ms程度余裕をあける
    constexpr double time_limit_inv = 1.0 / time_limit;
    constexpr double CLOCKS_PER_SEC_INV = 1.0 / CLOCKS_PER_SEC;
    inline double nowtime() { return CLOCKS_PER_SEC_INV * (clock() - start_clock); }
    inline bool intime() { return nowtime() < time_limit; }
    inline double progress() { return nowtime() * time_limit_inv; }
    struct preexec_dummy {
        preexec_dummy() {
            start_clock = clock();
        }
    } preexec_dummy_instance;
}

// [[/LIBRARY]]

constexpr ll d = 365;
constexpr ll z = 26;

ll calc_score(const vector<ll> &p, const vector<ll> &c, const vector<vector<ll>> &s) {
    ll score = 0;
    vector last(z, -1);
    REP(i, d) {
        ll j = p[i];
        score += s[i][j];
        score -= (i - last[j]) * (i - last[j] - 1) / 2 * c[j];
        last[j] = i;
    }
    REP(j, z) {
        const ll x = d-1 - last[j];
        score -= x * (x + 1) / 2 * c[j];
    }
    return score;
}

void output(const vector<ll> &ans) {
    FOREACH(x, ans) {
        say(x + 1);
    }
}

// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll dummy;
    
    cin >> dummy;
    vector<ll> c = qin(z);
    vector s(d, vector(z, (ll)0LL));
    REP(i, d) REP(j, z) cin >> s[i][j];

    vector jcand(d, vector(z, (ll)0LL));
    REP(i, d) {
        auto &r = jcand[i];
        iota(ALLOF(r), 0LL);
        sort(ALLOF(r), [&](ll x, ll y) {
            return s[i][x] > s[i][y];
        });
    }

    vector ans(d, (ll)0LL);
    ll score = -LINF;

    REP(i, d) {
        ll smax = -LINF;
        ans[i] = jcand[i][0];
    }
    score = calc_score(ans, c, s);

    vector<set<ll>> poss(z);
    REP(j, z) {
        poss[j].insert(-1);
        poss[j].insert(d);
    }
    REP(i, d) {
        ll j = ans[i];
        poss[j].insert(i);
    }

    ll epochs = 0;
    ll maxscore = score;
    ll debug_samples = 0;
    double debug_i_avg = 0;
    double debug_j_avg = 0;
    double debug_k_avg = 0;
    double debug_sij_avg = 0;
    double debug_cj_avg = 0;
    double debug_jprev_avg = 0;
    double debug_sijprev_avg = 0;
    double debug_cjprev_avg = 0;
    for (double t = 0; (t = marathon::progress()) <= 0.98; ) {
        REP(ganmo, 100) {
            
            // 行動決定
            ll i = xor128() % d;
            ll k = rand_uniform() * rand_uniform() * (t < 0.25 ? 4 : 8);
            ll j = jcand[i][k];

            // 行動書き換え・バッファリング
            ll jprev = ans[i];
            ans[i] = j;

            // 差分計算
            ll score2 = score;
            ll prev_prev, next_prev;
            auto previtr = poss[jprev].find(i);
            {
                auto litr = previtr;
                auto ritr = litr;
                litr--; ritr++;
                prev_prev = *litr, next_prev = *ritr;
            }
            poss[jprev].erase(previtr);
            auto curritr = poss[j].insert(i).first;
            ll prev_curr, next_curr;
            {
                auto litr = curritr;
                auto ritr = litr;
                litr--; ritr++;
                prev_curr = *litr, next_curr = *ritr;
            }
            score2 -= (next_prev - i) * (i - prev_prev) * c[jprev];
            score2 += (next_curr - i) * (i - prev_curr) * c[j];
            score2 -= s[i][jprev];
            score2 += s[i][j];

            // デバッグ表示
            if (DEBUG_MODE) {
                if (chmax(maxscore, score2)) {
                    // DUMP(tuple(i, k, pair(j, pair(s[i][j], c[j])), pair(jprev, pair(s[i][jprev], c[jprev]))));
                    debug_samples++;
                    debug_i_avg += i;
                    debug_k_avg += k;
                    debug_j_avg += j;
                    debug_sij_avg += s[i][j];
                    debug_cj_avg += c[j];
                    debug_jprev_avg += jprev;
                    debug_sijprev_avg += s[i][jprev];
                    debug_cjprev_avg += c[jprev];
                }
            }

            // 遷移判定
            bool accept = score < score2;
            if (!accept) {
                const double temp = 300 + 1000 * (1-t);
                if (rand_prob(exp((double)(score2 - score) / temp))) {
                    accept = true;
                }
            }
            
            // 遷移処理
            if (accept) {
                score = score2;
            } else {
                ans[i] = jprev;
                poss[j].erase(i);
                poss[jprev].insert(i);
            }
            
            epochs++;

        }
    }

    if (DEBUG_MODE) {
        debug_i_avg /= debug_samples;
        debug_k_avg /= debug_samples;
        debug_j_avg /= debug_samples;
        debug_sij_avg /= debug_samples;
        debug_cj_avg /= debug_samples;
        debug_jprev_avg /= debug_samples;
        debug_sijprev_avg /= debug_samples;
        debug_cjprev_avg /= debug_samples;
        DUMP(debug_i_avg);
        DUMP(debug_k_avg);
        DUMP(debug_j_avg);
        DUMP(debug_sij_avg);
        DUMP(debug_cj_avg);
        DUMP(debug_jprev_avg);
        DUMP(debug_sijprev_avg);
        DUMP(debug_cjprev_avg);
    }

    DUMP(tuple(score, epochs));
    output(ans);

}

Submission Info

Submission Time
Task A - AtCoder Contest Scheduling
User ganmodokix
Language C++ (GCC 9.2.1)
Score 123120736
Code Size 10449 Byte
Status AC
Exec Time 1977 ms
Memory 4408 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:158:12: warning: unused variable ‘smax’ [-Wunused-variable]
  158 |         ll smax = -LINF;
      |            ^~~~

Judge Result

Set Name test_ALL
Score / Max Score 123120736 / 365000000
Status
AC × 50
Set Name Test Cases
test_ALL test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt
Case Name Status Exec Time Memory
test_00.txt AC 1971 ms 4080 KB
test_01.txt AC 1967 ms 4332 KB
test_02.txt AC 1964 ms 4372 KB
test_03.txt AC 1971 ms 4192 KB
test_04.txt AC 1972 ms 4204 KB
test_05.txt AC 1974 ms 4196 KB
test_06.txt AC 1966 ms 4408 KB
test_07.txt AC 1971 ms 4208 KB
test_08.txt AC 1966 ms 4332 KB
test_09.txt AC 1967 ms 4288 KB
test_10.txt AC 1975 ms 4080 KB
test_11.txt AC 1967 ms 4372 KB
test_12.txt AC 1971 ms 4376 KB
test_13.txt AC 1967 ms 4188 KB
test_14.txt AC 1974 ms 4204 KB
test_15.txt AC 1968 ms 4136 KB
test_16.txt AC 1965 ms 4304 KB
test_17.txt AC 1970 ms 4080 KB
test_18.txt AC 1967 ms 4204 KB
test_19.txt AC 1970 ms 4192 KB
test_20.txt AC 1968 ms 4208 KB
test_21.txt AC 1972 ms 4188 KB
test_22.txt AC 1972 ms 4376 KB
test_23.txt AC 1964 ms 4284 KB
test_24.txt AC 1971 ms 4376 KB
test_25.txt AC 1973 ms 4188 KB
test_26.txt AC 1973 ms 4080 KB
test_27.txt AC 1971 ms 4080 KB
test_28.txt AC 1972 ms 4284 KB
test_29.txt AC 1970 ms 4076 KB
test_30.txt AC 1972 ms 4284 KB
test_31.txt AC 1967 ms 4376 KB
test_32.txt AC 1973 ms 4304 KB
test_33.txt AC 1971 ms 4076 KB
test_34.txt AC 1971 ms 4332 KB
test_35.txt AC 1973 ms 4136 KB
test_36.txt AC 1965 ms 4376 KB
test_37.txt AC 1964 ms 4136 KB
test_38.txt AC 1970 ms 4080 KB
test_39.txt AC 1967 ms 4376 KB
test_40.txt AC 1968 ms 4328 KB
test_41.txt AC 1972 ms 4376 KB
test_42.txt AC 1970 ms 4204 KB
test_43.txt AC 1977 ms 4292 KB
test_44.txt AC 1969 ms 4380 KB
test_45.txt AC 1972 ms 4336 KB
test_46.txt AC 1971 ms 4304 KB
test_47.txt AC 1971 ms 4192 KB
test_48.txt AC 1967 ms 4136 KB
test_49.txt AC 1969 ms 4140 KB