結果

問題 No.2390 Udon Coupon (Hard)
ユーザー soto800soto800
提出日時 2023-07-21 22:39:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,510 bytes
コンパイル時間 1,689 ms
コンパイル使用メモリ 171,436 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-22 00:11:23
合計ジャッジ時間 100,064 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,902 ms
5,248 KB
testcase_01 AC 1,902 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 1,902 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 1,901 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 1,902 ms
5,376 KB
testcase_09 AC 1,902 ms
5,376 KB
testcase_10 AC 1,902 ms
5,376 KB
testcase_11 AC 1,903 ms
5,376 KB
testcase_12 AC 1,902 ms
5,376 KB
testcase_13 AC 1,901 ms
5,376 KB
testcase_14 AC 1,902 ms
5,376 KB
testcase_15 AC 1,902 ms
5,376 KB
testcase_16 AC 1,902 ms
5,376 KB
testcase_17 AC 1,902 ms
5,376 KB
testcase_18 AC 1,902 ms
5,376 KB
testcase_19 AC 1,902 ms
5,376 KB
testcase_20 AC 1,901 ms
5,376 KB
testcase_21 AC 1,902 ms
5,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 1,901 ms
5,376 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 1,902 ms
5,376 KB
testcase_44 AC 1,902 ms
5,376 KB
testcase_45 AC 1,902 ms
5,376 KB
testcase_46 WA -
testcase_47 AC 1,902 ms
5,376 KB
testcase_48 AC 1,902 ms
5,376 KB
testcase_49 AC 1,902 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void solve()':
main.cpp:110:33: warning: 'target' may be used uninitialized [-Wmaybe-uninitialized]
  110 |             if(select<4)c[target]--;
      |                                 ^
main.cpp:71:13: note: 'target' was declared here
   71 |         lli target;
      |             ^~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
 
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

uint64_t rand64() {
    static uint64_t x = 88172645463325252ULL;
    x = x ^ (x << 7);
    return x = x ^ (x >> 9);
}
 
double rand_p() {
    return rand64() * (1.0 / UINT64_MAX);
}
 
void solve(){

    lli n;
    cin>>n;

    vector<lli> a(3),b(3);

    REP(i,0,3)cin>>a[i]>>b[i];

    mt19937 engine;
    std::chrono::system_clock::time_point start, endTime;

    start = std::chrono::system_clock::now();
    vector<lli> c(3,0);

    double maxD = 0;
    lli maxIndex = -1;
    REP(i,0,3){
        if(maxD < b[i]/(double)a[i]){
            maxIndex = i;
            maxD = b[i]/(double)a[i];
        }
    }


    c[maxIndex] = n / a[maxIndex];

    lli maxScore = c[maxIndex] * b[maxIndex];
    lli preScore = maxScore;

    lli loopCnt = 0;
    while(true){
        loopCnt++;
        endTime = std::chrono::system_clock::now();

        double nowElapsed = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - start).count();
        double finishElapsedMilisec = 1900;
        if(nowElapsed >= finishElapsedMilisec)break;

        lli select = engine()%6;

        lli target;

        if(select < 4){
            int target = engine()%3;
            c[target]++;

            lli nowCost = 0;
            REP(i,0,3){
                nowCost += a[i]*c[i];
            }
            if(nowCost > n){
                c[target]--;
                continue;
            }
        }
        else if(select < 6){
            int target = engine()%3;
            if(c[target]==0)continue;
            c[target]--;

            lli nowCost = 0;
            REP(i,0,3){
                nowCost += a[i]*c[i];
            }
            if(nowCost > n)continue;
        }

        lli nextScore = 0;
        REP(i,0,3)nextScore += b[i]*c[i];

        double start_temp = 5000.0, end_temp = 0;
        double temp = start_temp + (end_temp - start_temp) * (nowElapsed/(double)finishElapsedMilisec);
        double prob = std::exp((nextScore - preScore) / temp);
            

        if(prob > rand_p()){
            preScore = nextScore;
        }
        else{
            if(select<4)c[target]--;
            else if(select<6)c[target]++;
        }
        if(nextScore > maxScore){
            maxScore = nextScore;
        }
    }
    LOG(loopCnt);
    cout<<maxScore<<endl;

}

// Generated by 2.11.0 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){

    lli n=1;
    //cin>>n;
    std::random_device seed_gen;
    std::mt19937 engine(seed_gen());
    while(n--)solve();
    return 0;
}
0