Submission #116130

#TimeUsernameProblemLanguageResultExecution timeMemory
116130shayan_pArranging Tickets (JOI17_arranging_tickets)C++14
45 / 100
6059 ms640 KiB
// High above the clouds there is a rainbow... #include<bits/stdc++.h> #define F first #define S second #define PB push_back #define sz(s) int((s).size()) #define bit(n,k) (((n)>>(k))&1) using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int maxn=3010,mod=1e9+7; const ll inf=1e18; int a[maxn],b[maxn],n,m; ll c[maxn],val[maxn]; ll solve(){ ll ans=inf; for(int msk=0;msk<(1<<m);msk++){ memset(val,0,sizeof val); for(int i=0;i<m;i++){ if(bit(msk,i)){ for(int j=a[i];j!=b[i];j=(j+1)%n){ val[j]+=c[i]; } } else{ for(int j=b[i];j!=a[i];j=(j+1)%n){ val[j]+=c[i]; } } } ll mx=0; for(int i=0;i<n;i++){ mx=max(mx,val[i]); } ans=min(ans,mx); } return ans; } void print(){ cout<<n<<" "<<m<<endl; for(int i=0;i<m;i++){ cout<<a[i]<<" "<<b[i]<<" "<<c[i]<<endl; } } int arr[maxn]; vector<int>v[maxn]; priority_queue<int>pq; int best(){ int ans=0; for(int i=0;i<n;i++){ for(int x:v[i]) pq.push(x); while(arr[i]>0){ if(pq.empty() || pq.top()<i) return m+1; int x=pq.top(); pq.pop(); ans++; for(int k=i;k<x;k++) arr[k]--; } } return ans; } ll solve2(){ memset(val,0,sizeof val); for(int i=0;i<n;i++){ v[i].clear(); } for(int i=0;i<m;i++){ if(a[i]>b[i]) swap(a[i],b[i]); for(int j=a[i];j<b[i];j++) val[j]++; v[a[i]].PB(b[i]); } int ans=m; for(int ng=0;ng<m;ng++){ int l=-1,r=m; while(r-l>1){ int mid=(l+r)>>1; for(int j=0;j<n;j++){ arr[j]= (val[j] - mid + 1)/2; } while(sz(pq)){ pq.pop(); } if(best()>ng) l=mid; else r=mid; } ans=min(ans,r+ng); } return ans; } int main(){ ios_base::sync_with_stdio(false);cin.tie(0); cin>>n>>m; for(int i=0;i<m;i++) cin>>a[i]>>b[i]>>c[i]; return cout<<solve2()<<endl,0; } // Deathly mistakes: // * Read the problem curfully. // * Check maxn. // * Overflows.
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...