This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |