QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#669902 | #8936. Team Arrangement | gongmaohan | WA | 1ms | 3860kb | C++14 | 1.1kb | 2024-10-23 20:00:20 | 2024-10-23 20:00:20 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
int l[100], r[100];
int b[100], a[100];
int n;
int dp[100];
int calc(void){
for(int i=1;i<=n;i++) dp[i] = 0;
for(int i=1;i<=n;i++){
int mx = r[b[i]], mn = l[b[i]];
dp[i] = -1e15;
for(int j=i-1,k=1;j>=0;j--,k++){
if(mn <= k && k <= mx){
dp[i] = max(dp[i], dp[j] + a[k]);
}
mx = min(mx, r[b[j]]);
mn = max(mn, l[b[j]]);
}
}
// for(int i=1;i<=n;i++) cout << dp[i] << ' ';cout<<endl;
// cout<<endl;
return dp[n];
}
signed main(){
cin>>n;
for(int i=1;i<=n;i++)cin>>l[i]>>r[i];
for(int i=1;i<=n;i++)cin>>a[i];
double t = 100000000, tmd = 0.993; int ans = -1e15, res = -1e15;
for(int i=1;i<=n;i++) b[i] = i;
random_shuffle(b+1,b+n+1);
mt19937 rnd(time(0));
while(t>=1e-13){
int r = rnd()%(n-1)+2, l = rnd()%(r-1)+1;
swap(b[l], b[r]);
int tmp = calc();
if(tmp > ans){
ans = tmp;
}
else if(double(rnd()) <= exp(double(tmp - ans) / t) * double(1LL<<32)){
ans = tmp;
}
else{
swap(b[l], b[r]);
}
res = max(res, ans);
t *= tmd;
}
if(res < -1e15)cout << "impossible";
else cout << res << endl;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3856kb
input:
3 2 3 1 2 2 2 4 5 100
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
3 1 3 3 3 2 3 1 1 100
output:
100
result:
ok single line: '100'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3860kb
input:
2 1 1 2 2 1 1
output:
-999999999999999
result:
wrong answer 1st lines differ - expected: 'impossible', found: '-999999999999999'