QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#211531 | #5480. New Year Festival | bulijiojiodibuliduo# | ML | 0ms | 4156kb | C++17 | 2.0kb | 2023-10-12 17:55:31 | 2023-10-12 17:55:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const ll inf=1ll<<60;
const int N=(1<<11)+10;
ll ans=inf;
vector<PII> p[22];
int n,l[N],tt[N];
ll dp[N];
ll calc(int id,int t) {
if (t<p[id][0].fi) return inf;
if (t>p[id].back().fi) return inf;
auto c=lower_bound(all(p[id]),mp(t,-1));
if (c->fi==t) return c->se;
auto c0=prev(c);
return c0->se+(c->se-c0->se)/(c->fi-c0->fi)*(t-c0->fi);
}
set<int> mt;
map<int,VI> bg;
map<int,vector<pair<int,ll>>> upd;
int L[22],R[22];
void add(int j,int t) {
if (t>=L[j]&&t<=R[j]) {
mt.insert(t);
bg[t].pb(j);
}
}
int main() {
scanf("%d",&n);
rep(i,0,n) {
int m;
scanf("%d%d",&m,&l[i]);
rep(j,0,m) {
int x,y;
scanf("%d%d",&x,&y);
p[i].pb(mp(x,y));
}
L[i]=p[i][0].fi;
R[i]=p[i].back().fi;
}
rep(S,0,(1<<n)) rep(i,0,n) if (S&(1<<i)) tt[S]+=l[i];
rep(i,0,n) {
for (auto [x,y]:p[i]) {
add(i,x);
rep(S,0,(1<<n)) if (S&(1<<i)) {
rep(j,0,n) if (!(S&(1<<j))) {
add(j,x+tt[S]);
add(j,x+l[i]-tt[S]-l[j]);
}
}
}
}
rep(S,0,(1<<n)) dp[S]=inf;
dp[0]=0;
for (auto t:mt) {
for (auto [x,y]:upd[t]) dp[x]=min(dp[x],y);
for (auto c:bg[t]) {
ll v=calc(c,t);
rep(S,0,(1<<n)) if ((S&(1<<c))==0) {
upd[t+l[c]].pb(mp(S|(1<<c),dp[S]+v));
}
}
}
printf("%lld\n",dp[(1<<n)-1]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4156kb
input:
3 3 50 300 2500 350 0 400 3000 2 120 380 0 400 2400 4 160 0 800 400 0 450 100 950 4600
output:
1460
result:
ok single line: '1460'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
4 2 160 384 0 1000 2464 3 280 0 2646 441 0 1000 2795 1 160 544 0 2 240 720 0 1220 2000
output:
2022
result:
ok single line: '2022'
Test #3:
score: -100
Memory Limit Exceeded
input:
11 6 192168 0 8547618 626988 33627138 706274 36560720 1103426 50858192 1399013 55291997 1418093 55559117 6 161415 0 58611901 321482 57647455 349707 57534555 550744 55524185 885629 50500910 1448846 27972230 6 195811 0 6825079 56106 8339941 78686 8836701 323216 12993711 525834 15627745 1414450 2095944...
output:
1152921504606846976