結果
| 問題 |
No.2390 Udon Coupon (Hard)
|
| コンテスト | |
| ユーザー |
soto800
|
| 提出日時 | 2023-07-21 22:39:46 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 23 WA * 24 |
コンパイルメッセージ
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;
| ^~~~~~
ソースコード
#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;
}
soto800