Submission #412267

#TimeUsernameProblemLanguageResultExecution timeMemory
412267amoo_safarArranging Tickets (JOI17_arranging_tickets)C++17
0 / 100
7 ms10444 KiB
// vaziat meshki-ghermeze ! #include <bits/stdc++.h> #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " : " << x << '\n' using namespace std; typedef long long ll; typedef long double ld; typedef string str; typedef pair<ll, ll> pll; const ll Mod = 1000000007LL; const int N = 2e5 + 10; const ll Inf = 2242545357980376863LL; const ll Log = 30; vector<int> G[N], H[N]; int n, m; int to[N], frm[N], pk[N], M = 0; void Add_Edge(int u, int v){ frm[M] = u; to[M] = v; pk[M] = 1; G[u].pb(M); H[v].pb(M); M ++; } int ps[N]; int Solve(int l, int r, int dif){ memset(ps, 0, sizeof ps); multiset<int> ms; int res = 0; for(int i = l; i < r - 1; i++){ for(auto x : G[i]){ if(x >= r) continue; ps[i] ++; ps[x] --; ms.insert(x); } ps[i] += ps[i - 1]; while(ps[i] > dif){ int fr = *ms.rbegin(); ms.erase(ms.find(fr)); ps[i] -= 2; ps[fr] += 2; res ++; } } return res + dif; } int Calc(int i, int dif){ if(i > n) i -= n; return Solve(i, i + n, dif); } int df[N]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; int a, b, c; for(int i = 0; i < m; i++){ cin >> a >> b >> c; assert(c == 1); if(a > b) swap(a, b); df[a] ++; df[b] --; Add_Edge(a, b); Add_Edge(b, n + a); Add_Edge(n + a, n + b); } for(int i = 1; i <= n; i++) df[i] += df[i - 1]; int id_mx = max_element(df + 1, df + n) - df; id_mx ++; int ans = min(Calc(id_mx, 0), Calc(id_mx, 1)); for(int i = 1; i <= n; i++) ans = min(ans, Calc(i, 0)); cout << ans << '\n'; return 0; }
#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...