답안 #116133

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
116133 2019-06-10T18:30:58 Z shayan_p Arranging Tickets (JOI17_arranging_tickets) C++14
0 / 100
2 ms 384 KB
// 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) assert(0);
	    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++){
	int A=a[i],B=b[i];
	if(A>B) swap(A,B);
	
	for(int j=A;j<B;j++)
	    val[j]++;
	v[A].PB(B);
    }
    for(int i=0;i<n;i++){
	arr[i]= (val[i]+1)/2;
    }
    return best();
}

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];

    ll ans=inf;
    for(int i=0;i<n;i++){
	ans=min(ans,solve2());
	for(int j=0;j<m;j++)
	    a[i]=(a[i]+n-1)%n, b[i]=(b[i]+1)%n;
    }
 
    return cout<<ans<<endl,0;
}
// Deathly mistakes:
//  * Read the problem curfully.
//  * Check maxn.
//  * Overflows.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -