Submission #55025

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

LL two(vector<vector<LL> > z, LL n){
	LL maxcross = 0;
	LL numcross[n][n];

	vector<LL> ends(n, 0);
	vector<LL> backs[n];
	for(int j = 0; j < z.size(); j++){
		int c = z[j][0];
		int d = z[j][1];
		ends[c]++;
		ends[d]++;
		backs[d].push_back(c);
	}
	for(int a = 0; a < n; a++){
		LL f = 0;
		for(int b = a+1; b < n; b++){
			f += ends[b];
			for(int r : backs[b]){
				if(r >= a+1){
					f -= 2;
				}
			}
			numcross[a][b] = f;
			maxcross = max(maxcross, numcross[a][b]);
		}
	}

	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...