2023 rcpc
This commit is contained in:
88
2023/rcpc/d2/editorial/l-dush-682.cpp
Normal file
88
2023/rcpc/d2/editorial/l-dush-682.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define int long long
|
||||
|
||||
const int inf = 1e18;
|
||||
|
||||
int n,m;
|
||||
int tip[25],a[25];
|
||||
int s[100005],d[100005],t[100005];
|
||||
int dp[(1 << 20) + 5];///timpul minim la care mask isi fac dus
|
||||
vector<pair<int,int>>interv[3];
|
||||
int topt[25][100005];
|
||||
|
||||
void prec()
|
||||
{
|
||||
for (int om = 0; om < n; om++)
|
||||
{
|
||||
int tp = tip[om];
|
||||
int lg = a[om];
|
||||
topt[om][interv[tp].size()] = inf;
|
||||
for (int i = interv[tp].size() - 1; i >= 0; i--)
|
||||
{
|
||||
topt[om][i] = topt[om][i + 1];
|
||||
if (interv[tp][i].second >= lg)
|
||||
topt[om][i] = interv[tp][i].first + lg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int f(int ti,int om)
|
||||
{
|
||||
if (ti == inf)
|
||||
return inf;
|
||||
int st = -1,pas = 1 << 16;
|
||||
while (pas != 0)
|
||||
{
|
||||
if (st + pas < interv[tip[om]].size() and interv[tip[om]][st + pas].first <= ti)
|
||||
st += pas;
|
||||
pas /= 2;
|
||||
}
|
||||
///st este ultimul interval cu s <= ti
|
||||
int timp = inf;
|
||||
if (st != -1)
|
||||
{
|
||||
if (interv[tip[om]][st].first + interv[tip[om]][st].second - ti >= a[om])
|
||||
timp = ti + a[om];
|
||||
}
|
||||
if (timp == inf and st + 1 != interv[tip[om]].size())
|
||||
{
|
||||
timp = topt[om][st + 1];
|
||||
}
|
||||
//cout << ti << ' ' << om << ' ' << timp << '\n';
|
||||
return timp;
|
||||
}
|
||||
|
||||
signed main()
|
||||
{
|
||||
ios_base::sync_with_stdio(false);
|
||||
cin.tie(NULL);
|
||||
cout.tie(NULL);
|
||||
cin >> n >> m;
|
||||
for (int i = 0; i < n; i++)
|
||||
cin >> tip[i] >> a[i],tip[i]++;
|
||||
for (int i = 1; i <= m; i++)
|
||||
{
|
||||
cin >> s[i] >> d[i] >> t[i],t[i]++;
|
||||
interv[t[i]].push_back({s[i],d[i]});
|
||||
}
|
||||
prec();
|
||||
for (int mask = 1; mask < (1 << n); mask++)
|
||||
{
|
||||
int minim = inf;
|
||||
for (int bit = 0; bit < n; bit++)
|
||||
{
|
||||
if ((mask & (1 << bit)) != 0)
|
||||
{
|
||||
int tant = dp[mask - (1 << bit)];
|
||||
minim = min(minim,f(tant,bit));
|
||||
}
|
||||
}
|
||||
dp[mask] = minim;
|
||||
//cout << dp[mask] << '\n';
|
||||
}
|
||||
cout << dp[(1 << n) - 1];
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user