QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#500025 | #6962. Far Away from Home | inksamurai | AC ✓ | 3647ms | 96624kb | C++23 | 1.5kb | 2024-07-31 21:21:40 | 2024-07-31 21:21:42 |
Judging History
answer
#include <bits/stdc++.h>
#define int ll
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int) a.size()
#define all(a) a.begin(),a.end()
#define vec(...) vector<__VA_ARGS__>
#define _3Wcdivh ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
const int inf=1e9;
void slv(){
int n,c;
cin>>n>>c;
vec(vi) rs(c);
rep(i,n){
int x,k;
cin>>x>>k;
rep(j,k){
int v;
cin>>v;
v-=1;
rs[v].pb(x);
}
}
map<int,int> ad,cof;
auto push=[&](int l,int r,int c,int x){
if(l>r) return;
ad[l]+=x;
cof[l]+=c;
ad[r+1]-=x;
cof[r+1]-=c;
};
rep(v,c){
vi vc=rs[v];
sort(all(vc));
const int si=sz(vc);
assert(si);
rep(i,si-1){
int l=vc[i],r=vc[i+1];
push(l,(l+r)/2,1,-l);
push((l+r)/2+1,r-1,-1,r);
}
push(0,vc[0]-1,-1,vc[0]);
push(vc.back(),inf,1,-vc.back());
}
// print(ad[0]);
vi tmp;
for(auto p:ad){
tmp.pb(p.fi);
}
int ans=1e18;
int cur_ad=0,cur_cof=0;
rep(i,sz(tmp)){
int v=tmp[i];
if(v>inf) break;
cur_cof+=cof[v];
cur_ad+=ad[v];
ans=min(ans,cur_ad+cur_cof*v);
}
print(ans);
}
signed main(){
_3Wcdivh;
int __t;
cin>>__t;
rep(cs,__t){
slv();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3647ms
memory: 96624kb
input:
5 99674 20 763240852 6 13 12 1 19 14 15 907986528 9 9 13 2 3 10 5 8 11 20 405330475 5 8 20 18 19 7 350664157 3 14 7 11 866108800 7 5 15 19 17 7 1 16 243752093 3 5 6 16 957293963 7 6 2 7 12 3 8 11 87866078 8 8 15 2 10 16 4 5 18 599501459 4 15 20 10 13 75898433 3 15 1 13 634860118 3 4 10 12 931882462 ...
output:
8461 225014484653807 4191726 32192409196439 2242332818199
result:
ok 5 lines