Submission #1077221

#TimeUsernameProblemLanguageResultExecution timeMemory
1077221LCJLYArranging Tickets (JOI17_arranging_tickets)C++14
10 / 100
628 ms600 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef array<int,4>pi2;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

void solve(){ 	
	int n,m;
	cin >> n >> m;
	pii arr[m];
	int temp,temp2,temp3;
	for(int x=0;x<m;x++){
		cin >> temp >> temp2 >> temp3;
		temp--;
		temp2--;
		if(temp>temp2) swap(temp,temp2);
		arr[x]={temp,temp2};
	}
	
	int mini=1e15;
	for(int x=0;x<(1<<m);x++){
		int dp[n+5];
		memset(dp,0,sizeof(dp));
		for(int y=0;y<m;y++){
			if(x&(1<<y)){
				int cur=arr[y].second;
				while(cur!=arr[y].first){
					dp[cur]++;
					cur=(cur+1)%n;
				}
			}
			else{
				int cur=arr[y].first;
				while(cur!=arr[y].second){
					dp[cur]++;
					cur=(cur+1)%n;
				}
			}
		}
		int maxi=0;
		for(int x=0;x<n;x++){
			maxi=max(maxi,dp[x]);
		}
		mini=min(mini,maxi);
	}
	cout << mini;
}

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin >> t;
	//freopen("hand.txt","r",stdin);
	while(t--){
		solve();
	}
}
#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...