Submission #55023

#TimeUsernameProblemLanguageResultExecution timeMemory
55023ksun48Arranging Tickets (JOI17_arranging_tickets)C++14
45 / 100
6027 ms6392 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

LL brute(vector<vector<LL> > z, LL n){
	LL best = z.size();
	for(LL r = 0; r < (1 << z.size()); r++){
		vector<LL> freq(n,0);
		for(int j = 0; j < z.size(); j++){
			LL c = z[j][0];
			LL d = z[j][1];
			if(r & (1 << j)){
				swap(c,d);
			}
			while(c != d){
				freq[c]++;
				c++;
				c %= n;
			}
		}
		LL maxused = 0;
		for(int j = 0; j < n; j++){
			maxused = max(maxused, freq[j]);
		}
		best = min(best, maxused);
	}
	return best;
}

LL two(vector<vector<LL> > z, LL n){
	LL maxcross = 0;
	LL numcross[n][n];
	for(int a = 0; a < n; a++){
		for(int b = a+1; b < n; b++){
			LL cross = 0;
			for(int j = 0; j < z.size(); j++){
				int parity = 0;
				LL c = z[j][0];
				LL d = z[j][1];
				if(a + 1 <= c && c <= b) parity ^= 1;
				if(a + 1 <= d && d <= b) parity ^= 1;
				cross += parity;
			}
			numcross[a][b] = cross;
			maxcross = max(maxcross, cross);
		}
	}
	LL realbound = (maxcross + 1) / 2;
	for(int a = 0; a < n; a++){
		for(int c = a+1; c < n; c++){
			if(numcross[a][c] != maxcross) continue;
			for(int b = a+1; b < c; b++){
				for(int d = c+1; d < n; d++){
					if(numcross[b][d] != maxcross) continue;
					if(numcross[a][c] % 2 == 0 && numcross[a][b] % 2 == 1){
						realbound = maxcross / 2 + 1;
					}
				}
			}
		}
	}
	return realbound;
}

int main(){
	cin.sync_with_stdio(0); cin.tie(0);
	LL n, m;
	cin >> n >> m;
	// stations 1 to n
	vector<vector<LL> > z;
	for(int i = 0; i < m; i++){
		LL a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		if(a > b) swap(a,b);
		for(int j = 0; j < c; j++){
			z.push_back(vector<LL>({a,b}));
		}
	}
	LL bound = two(z, n);
	cout << bound << '\n';
}
#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...