QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#211564 | #5480. New Year Festival | bulijiojiodibuliduo# | WA | 1ms | 3780kb | C++17 | 2.3kb | 2023-10-12 18:28:50 | 2023-10-12 18:28:50 |
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 int inf=1234567890;
const int N=(1<<11)+10;
int ans=inf;
vector<PII> p[22],bg[22];
int n,l[N],tt[N];
vector<pair<int,int>> dp[N];
int 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);
}
int L[22],R[22];
void add(int j,int t) {
if (t>=L[j]&&t<=R[j]) {
bg[j].pb(mp(t,calc(j,t)));
}
}
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(i,0,n) sort(all(bg[i]));
dp[0].pb({0,0});
VI ord;
rep(S,0,(1<<n)) ord.pb(S);
sort(all(ord),[&](int a,int b) {
return __builtin_popcount(a)<__builtin_popcount(b);
});
for (auto S:ord) {
sort(all(dp[S]));
rep(j,0,n) if ((S&(1<<j))==0) {
int r=0;
int cs=inf;
int pmx=inf;
for (auto [t,sc]:bg[j]) {
while (r<SZ(dp[S])&&dp[S][r].fi<=t) {
cs=min(dp[S][r].se,cs);
r++;
}
if (cs+sc<pmx) {
pmx=cs+sc;
dp[S|(1<<j)].pb(mp(t+l[j],cs+sc));
}
}
}
if (S!=(1<<n)-1) dp[S].clear();
}
for (auto [t,sc]:dp[(1<<n)-1]) ans=min(ans,sc);
printf("%d\n",ans);
printf("%d\n",(int)clock());
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3780kb
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 395
result:
wrong output format Extra information in the output file